Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent

Hello,

How can I access a Model's properties in a Controller in Laravel?

In my User model I have this array:

protected $sortable = [
    'first_name',
    'last_name',
    'email',
];

and I created a getter:

public function getSortable()
{
    return $this->sortable;
}

Then, in my UserController I have:

namespace App\Http\Controllers;
...
use App\User;

class UserController extends Controller
{
    public function index()
    {
        // here I'd like to get the $sortable array
    }
}

Thank you

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ivanhalen ivanhalen Joined 8 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.