Access Controller method from another controller in Laravel 5

You can access your controller method like this: app(‘App\Http\Controllers\PrintReportController’)->getPrintReport(); This will work, but it’s bad in terms of code organisation (remember to use the right namespace for your PrintReportController) You can extend the PrintReportController so SubmitPerformanceController will inherit that method class SubmitPerformanceController extends PrintReportController { // …. } But this will also inherit all other … Read more

How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?

Given it’s a raw expression, you should use DB::raw() to set CURRENT_TIMESTAMP as a default value for a column: $table->timestamp(‘created_at’)->default(DB::raw(‘CURRENT_TIMESTAMP’)); This works flawlessly on every database driver. As of Laravel 5.1.25 (see PR 10962 and commit 15c487fe) you can now use the new useCurrent() column modifier method to achieve the same default value for a … Read more

Laravel: How to Get Current Route Name? (v5 … v7)

Try this Route::getCurrentRoute()->getPath(); or \Request::route()->getName() from v5.1 use Illuminate\Support\Facades\Route; $currentPath= Route::getFacadeRoot()->current()->uri(); Laravel v5.2 Route::currentRouteName(); //use Illuminate\Support\Facades\Route; Or if you need the action name Route::getCurrentRoute()->getActionName(); Laravel 5.2 route documentation Retrieving The Request URI The path method returns the request’s URI. So, if the incoming request is targeted at http://example.com/foo/bar, the path method will return foo/bar: $uri … Read more

Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

According to the official Laravel 7.x documentation, you can solve this quite easily. Update your /app/Providers/AppServiceProvider.php to contain: use Illuminate\Support\Facades\Schema; /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191); } Alternatively, you may enable the innodb_large_prefix option for your database. Refer to your database’s documentation for instructions on … Read more

Laravel Migration Change to Make a Column Nullable

Laravel 5 now supports changing a column; here’s an example from the offical documentation: Schema::table(‘users’, function($table) { $table->string(‘name’, 50)->nullable()->change(); }); Source: http://laravel.com/docs/5.0/schema#changing-columns Laravel 4 does not support modifying columns, so you’ll need use another technique such as writing a raw SQL command. For example: // getting Laravel App Instance $app = app(); // getting laravel … Read more

Laravel 5 – artisan seed [ReflectionException] Class SongsTableSeeder does not exist

You need to put SongsTableSeeder into file SongsTableSeeder.php in the same directory where you have your DatabaseSeeder.php file. And you need to run in your console: composer dump-autoload to generate new class map and then run: php artisan db:seed I’ve just tested it. It is working without a problem in Laravel 5

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)