We can send On Demand Notifications using the Notification facade using an only email address. This is feature is available since Laravel 5.5 and above. I hope you like this Post, Please feel free to comment below, your […]
Laravel Drop all tables
This is useful for migrations when you can’t rollback. It can easily be run in artisan mode or you can create a console command.
1 2 3 4 |
foreach(\DB::select('SHOW TABLES') as $table) { $table_array = get_object_vars($table); \Schema::drop($table_array[key($table_array)]); } |
How to check current installed version of Laravel ?
You can use laravel’s artisan command to check currently installed version of Laravel Framework Version of Laravel Issue below command from your terminal, make sure to be in application root while issuing command. […]
Last executed queries in Laravel5
You can use getQueryLog() method to get most recently executed queries. But in Laravel 5.1 it is disabled by default. So you have to enable it first.To enable you need to call DB::connection()->enableQueryLog();
1 |
DB::getQueryLog(); |
Getting all tables inside a database using Laravel
Here is the simple code snippet to get all the tables under the database in laravel framework.
1 2 |
$tables = DB::select('SHOW TABLES'); dd($tables); |
Injecting data With Blade
1 2 3 4 |
// categoriesCount.blade.php @inject('categories','App\categories') Total categories : {{ $categories->count(); }} |
1 2 3 4 5 6 7 8 |
// routes.php view::composer('categories',function($view){ $view->with('categories','App\categories'); }); // categoriesCount.blade.php Total categories : {{ $categories->count(); }} |
Named Route Groups
1 2 3 4 5 6 7 |
Route::get('admin/home',['as' => 'home',function(){ echo 'admin home'; }]); // view echo route('home'); // output : http://localhost/admin/home |
1 2 3 4 5 6 7 8 |
Route::group(['prefix' => 'admin'],function(){ Route::get('home',['as' => 'home',function(){ echo 'admin home'; }]); }); // view echo route('home'); // output : http://localhost/admin/home |
1 2 3 4 5 6 7 8 |
Route::group(['prefix' => 'admin','as' => 'admin'],function(){ Route::get('home',['as' => 'home',function(){ echo 'admin home'; }]); }); // view echo route('admin.home'); // output : http://localhost/admin/home |
Get table column names as array from Eloquent model
1 2 3 4 5 6 7 |
class NewMediaModel extends Model { public function getTableColumns() { return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable()); } } |
Show All Validation Errors in Laravel’s Blade View
1 2 3 4 5 |
@if($errors->has()) @foreach ($errors->all() as $error) <div>{{ $error }}</div> @endforeach @endif |