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”
Category: Frameworks
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”
Converting object values to array values
Laravel query returns values as objects. When you need to convert it into array values, you can use any one of the following:
Method 1: Using PHP’s array_map
function
$db_results = array_map(function($result){
return (array) $result;
}, $db_results);
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”
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”
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.
Installing Laravel Framework on Ubuntu 16.04 using AWS EC2
One of the popular PHP framework – Laravel can be installed in Ubuntu using composer.
To setup an EC2 instance with Ubuntu 16.04, read this post. To set up LAMP stack, read this post.
Continue reading “Installing Laravel Framework on Ubuntu 16.04 using AWS EC2”