Displaying the Error Messages in Laravel after being Redirected from controller

Laravel 4 When the validation fails return back with the validation errors. if($validator->fails()) { return Redirect::back()->withErrors($validator); } You can catch the error on your view using @if($errors->any()) {{ implode(”, $errors->all(‘<div>:message</div>’)) }} @endif UPDATE To display error under each field you can do like this. <input type=”text” name=”firstname”> @if($errors->has(‘firstname’)) <div class=”error”>{{ $errors->first(‘firstname’) }}</div> @endif For better … Read more

Timestamps are not updating while attaching data in pivot table

If you want your pivot table to have automatically maintained created_at and updated_at timestamps, use the withTimestamps() method on the relationship definition. return $this->belongsToMany(‘Role’)->withTimestamps(); For Laravel 4.2: Working With Pivot Tables Laravel 5.0: Working With Pivot Tables Laravel 5.1: Retrieving Intermediate Table Columns Laravel 5.2: Filtering Relationships Via Intermediate Table Columns Laravel 5.3: Filtering Relationships … Read more

laravel with() method versus load() method

Both accomplish the same end results—eager loading a related model onto the first. In fact, they both run exactly the same two queries. The key difference is that with() eager loads the related model up front, immediately after the initial query (all(), first(), or find(x), for example); when using load(), you run the initial query … Read more

How Can I Remove “public/index.php” in the URL Generated Laravel?

Option 1: Use .htaccess If it isn’t already there, create an .htaccess file in the Laravel root directory. Create a .htaccess file your Laravel root directory if it does not exists already. (Normally it is under your public_html folder) Edit the .htaccess file so that it contains the following code: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule … Read more

Laravel: Where to store global arrays data and constants?

For most constants used globally across the application, storing them in config files is sufficient. It is also pretty simple Create a new file in the app/config directory. Let’s call it constants.php In there you have to return an array of config values. return [ ‘langs’ => [ ‘es’ => ‘www.domain.es’, ‘en’ => ‘www.domain.us’ // … Read more

How to get a list of registered route paths in Laravel?

Route::getRoutes() returns a RouteCollection. On each element, you can do a simple $route->getPath() to get path of the current route. Each protected parameter can be get with a standard getter. Looping works like this: $routeCollection = Illuminate\Support\Facades\Route::getRoutes(); foreach ($routeCollection as $value) { echo $value->getPath(); }