Laravel 5 TIPS For Beginners!

Here are some tips you might find handy when you think you have done everything according to the tutorials!

In formrequests to authorise access only for registered/signed users we add

use Auth;
public function authorize()
if ( !Auth::check() )
return false;
return true;

Get user id in view files and controllers:

{{ Auth::user()->id }}

In controllers do not forget to include:

use Auth;

In controllers we always include the models we use and the formrequests we use:

use appname\Model1;
use appname\Model2;
use appname\Model3;
use Auth;
use appname\Http\Requests\ItemFormRequest;

In every model do not forget to declare which columns/fields will be accessible!

protected $fillable = ['column1', 'column2']

Display errors in view files with forms

@if(count($errors) > 0)
<ul class="alert alert-danger">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>

Change application name:

php artisan app:name myapp //create unique namespace!

You can declare all routes in route.php

Route::resource('item', 'ItemController');

For forms and strings which contain code that you do not want to be character escaped use:

{!! !!} instead of {{{ }}}

Polyvios Damianakis

Polyvios Damianakis

Biography to be completed

More Posts - Website

Follow Me: