Posted in Laravel, PHP

Route Model Binding : Multiple Route Key

When using Implicit Model Binding, you can use getRouteKeyName  to use alternative column such as slug instead of id to inject a model instance directly inside routes. Now, model can be bound only with slug column. When you think to use id, the binding fails.  Continue reading “Route Model Binding : Multiple Route Key”

Posted in Laravel, PHP

Implicit Model Binding : Changing Model’s Route Key

When using Implicit Model Binding, the model can be fetched using the id parameter by default. Consider when you need to list product details for an id, you use:

Route::get('product/{id}', 'ContactsController@index');

Continue reading “Implicit Model Binding : Changing Model’s Route Key”

Posted in Laravel

Securely setting file permissions for Laravel Framework

After developing the application locally, when the application is moved to production, people find that web page fails to display the content. This may be due to proper file permissions. Some simply gives complete read, write and execute permission for files and directories like this:

sudo chmod -R 777 path/to/root

which is a serious security concern. Follow these steps to securely grant permissions to your files:

Continue reading “Securely setting file permissions for Laravel Framework”

Posted in Laravel

Add multiple contents to @yield from @section

Sometimes, we may extend/include more than one template inside a layout. When we need to define a section of content in a single yield, it perfectly does its job. But when there is a situation that needs to include multiple sections inside a single yield, the first section is overridden by the next section resulting in displaying only the last section in the yield directive.

Continue reading “Add multiple contents to @yield from @section”

Posted in Laravel

Change order of migration in Laravel

When tables are migrated in Laravel with foreign key checks, MySQL doesn’t allow us to create a foreign key reference to the parent table from the child table without parent table being created. Sometimes, when we create migrations, we would have ended up creating a child table before a parent table is created. But still, there is a way to change the order of execution of table migrations.

Continue reading “Change order of migration in Laravel”