Optional parameter in the middle of a route

No. Optional parameters need to go to the end of the route, otherwise Router wouldn’t know how to match URLs to routes. What you implemented already is the correct way of doing that: get(‘things/entities’, ‘MyController@doSomething’); get(‘things/{id}/entities’, ‘MyController@doSomething’); You could try doing it with one route: get(‘things/{id}/entities’, ‘MyController@doSomething’); and pass * or 0 if you want … Read more

Has many through many-to-many

If you want to have a custom relation, you can create your own extends to Relation abstract class. For example: BelongsToManyThought. But if you don’t want to implement a Relation, I think that it can fulfill your needs : In App\Deal.php, you can combine the solution of @thomas-van-der-veen public function metrics() { return Metric ::join(‘metric_product’, … Read more

CONCAT columns with Laravel 5 eloquent

You need to wrap your query in DB::raw: $comp = Component::select(DB::raw(“CONCAT(‘name’,’id’) AS ID”))->get() Also, note because you are doing your query like this, your model might behave differently, because this select removes all other fields from the select statement. So you can’t read the other fields from your model without a new query. So ONLY … Read more

Laravel parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE

Laravel 5.1 uses the ::class property to get string representations of a fully qualified classname. The error you’re seeing is caused by this line $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); This language feature has been introduced in PHP 5.5 which is a requirement of Laravel 5.1. Your installed PHP version is probably older than 5.5. Try to update … Read more