@raheelkhan What, exactly, are you trying to accomplish? Why are you just creating constants with exactly the same name as your column names, instead of just referencing your column names directly?
Oct 22, 2020
11
Level 1
Model Approach like ASP.NET MVC in Laravel
I am trying to achieve something similar to the Dot Net framework in Laravel. As we declare all of our table columns in the Model and in the controller we can simply call them using model object.
- WHAT I WANT (Something Similar)
public function functionaName(){
$object = ModelName::class
$items = Item::select($object->name1, $object->name2)->get()
return view('welcome', compact('items');
}
And want to achieve the same in Blade's view as well.
- Currently, what I am doing is;
That I have created constant fields in my Model
public const ItemName = "ItemName";
public const ItemQuantity = "Quantity";
and In my Controller, I used them like
$items = Item::select(Item::ItemName, Item::ItemQuantity)->get();
is this the right approach? if not, then what is the best approach?
Thank you
Level 80
@raheelkhan If you’re just wanting autocomplete, then look into https://github.com/barryvdh/laravel-ide-helper
Please or to participate in this conversation.