laravel-5.2

How to access url segment in controller in laravel 5.2

只谈情不闲聊 提交于 2021-01-27 05:41:39
问题 I am working in Laravel 5.2 and i want to access URL segments in my controller. I am using echo Request::segment(2); but nothing is print. How can i get values from url in controller. 回答1: In laravel 5.2 you can do it this way.. echo request()->segment(2); request() is one of the several helper functions provided in Laravel 5.2. It returns the current request object thus you don't need use statement for the facade on the top of your class. 回答2: In Laravel 7, I am using this to get segments

How to fix error Base table or view not found: 1146 Table laravel relationship table?

五迷三道 提交于 2021-01-26 03:10:36
问题 I am a new of laravel I try to create relationship many to many between table,My problem when I am insert data in to database I got errors QueryException in Connection.php line 713: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'learn.category_posts' doesn't exist (SQL: insert into category_posts ( category_id , posts_id ) values (4, )) can anyone help me pls . and here below is my migrate and code: 2016_08_04_131009_create_table_posts.php public function up() { Schema::create(

How to fix error Base table or view not found: 1146 Table laravel relationship table?

我与影子孤独终老i 提交于 2021-01-26 03:08:29
问题 I am a new of laravel I try to create relationship many to many between table,My problem when I am insert data in to database I got errors QueryException in Connection.php line 713: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'learn.category_posts' doesn't exist (SQL: insert into category_posts ( category_id , posts_id ) values (4, )) can anyone help me pls . and here below is my migrate and code: 2016_08_04_131009_create_table_posts.php public function up() { Schema::create(

Check if variable exist in laravel's blade directive

≯℡__Kan透↙ 提交于 2021-01-20 16:23:54
问题 I'm trying to create blade directive which echo variable (if variable defined) or echo "no data" if variable undefined. This is my code in AppServiceProvider.php : <?php namespace App\Providers; use Blade; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { Blade::directive('p', function($ex) { error_log(print_r($ex,true)); return '<?php $defined_vars = get_defined

Check if variable exist in laravel's blade directive

夙愿已清 提交于 2021-01-20 16:20:50
问题 I'm trying to create blade directive which echo variable (if variable defined) or echo "no data" if variable undefined. This is my code in AppServiceProvider.php : <?php namespace App\Providers; use Blade; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { Blade::directive('p', function($ex) { error_log(print_r($ex,true)); return '<?php $defined_vars = get_defined

Check if variable exist in laravel's blade directive

♀尐吖头ヾ 提交于 2021-01-20 16:16:06
问题 I'm trying to create blade directive which echo variable (if variable defined) or echo "no data" if variable undefined. This is my code in AppServiceProvider.php : <?php namespace App\Providers; use Blade; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { Blade::directive('p', function($ex) { error_log(print_r($ex,true)); return '<?php $defined_vars = get_defined

Run composer dump-autoload from controller in laravel 5

这一生的挚爱 提交于 2021-01-15 18:39:05
问题 I want to run composer dump-autoload without shell command in controller. In laravel 4 I use Artisan::call('dump-autoload'); but in laravel 5 this command not work. 回答1: Artisan is not wrapper for composer . Composer itself brings the composer command to control itself. Currently there is no way to call composer commands in a proper way from Artisan - not even with creating your own Artisan command with php artisan make:console CommandName . Unless you don't want to use PHPs exec or system ,

Run composer dump-autoload from controller in laravel 5

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-15 18:36:52
问题 I want to run composer dump-autoload without shell command in controller. In laravel 4 I use Artisan::call('dump-autoload'); but in laravel 5 this command not work. 回答1: Artisan is not wrapper for composer . Composer itself brings the composer command to control itself. Currently there is no way to call composer commands in a proper way from Artisan - not even with creating your own Artisan command with php artisan make:console CommandName . Unless you don't want to use PHPs exec or system ,

Eloquent morphTo()->withTrashed() stopped working

坚强是说给别人听的谎言 提交于 2021-01-06 04:24:07
问题 I have a polymorphic relationship set up in an OrderItem model, where saleable can be a few different models. I've set it up like any other relationship: public function saleable() { return $this->morphTo()->withTrashed(); } This used to work fine, now all of a sudden it doesn't work and it throws the error: Call to undefined method Illuminate\Database\Query\Builder::withTrashed() I don't understand why it would have stopped working, possibly due to a composer update which may have updated