2017-02-09 9 views
0

Я новичок в laravel 5.3, и я учусь, но у меня есть проблема, с которой я не могу решить, может быть, кто-то может мне помочь. Я хочу показать таблицу (около) с помощью некоторых кнопок действий. Когда я просматриваю index.blade, я получаю excetion в своих журналах и не вижу таблицу. No tableПопробуйте показать таблицу с кнопками действий - laravel 5.3 и dataTables.min.js

С помощью инструмента разработки от хром я получаю статус 500.

Первый трассировки стека

Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getForDataTable() on null in /var/www/html/heincloud/app/Http/Controllers/Backend/About/AboutTableController.php:26 
Stack trace: 
#0 [internal function]: App\Http\Controllers\Backend\About\AboutTableController->__invoke(Object(App\Http\Requests\Backend\About\ManageAboutRequest)) 
#1 /var/www/html/heincloud/bootstrap/cache/compiled.php(9584): call_user_func_array(Array, Array) 
#2 /var/www/html/heincloud/bootstrap/cache/compiled.php(9611): Illuminate\Routing\Controller->callAction('__invoke', Array) 
#3 /var/www/html/heincloud/bootstrap/cache/compiled.php(8665): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\Backend\About\AboutTableController), '__invoke') 
#4 /var/www/html/heincloud/bootstrap/cache/compiled.php(8646): Illuminate\Routing\Route->runController() 
#5 /var/www/html/heincloud/bootstrap/cache/compiled.php(8355): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request)) 
#6 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#7 /var/www/html/heincloud/app/Http/Middleware/SessionTimeout.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#8 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): App\Http\Middleware\SessionTimeout->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#9 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#10 /var/www/html/heincloud/app/Http/Middleware/RouteNeedsPermission.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#11 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): App\Http\Middleware\RouteNeedsPermission->handle(Object(Illuminate\Http\Request), Object(Closure), 'view-backend') 
#12 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#13 /var/www/html/heincloud/app/Http/Middleware/LocaleMiddleware.php(57): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#14 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): App\Http\Middleware\LocaleMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#15 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#16 /var/www/html/heincloud/bootstrap/cache/compiled.php(10177): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#17 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#18 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#19 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(43): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#20 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): Illuminate\Auth\Middleware\Authenticate->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#21 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#22 /var/www/html/heincloud/bootstrap/cache/compiled.php(3312): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#23 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#24 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#25 /var/www/html/heincloud/bootstrap/cache/compiled.php(13749): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#26 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#27 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#28 /var/www/html/heincloud/bootstrap/cache/compiled.php(12155): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#29 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#30 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#31 /var/www/html/heincloud/bootstrap/cache/compiled.php(13495): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#32 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#33 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#34 /var/www/html/heincloud/bootstrap/cache/compiled.php(13432): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#35 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#36 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#37 /var/www/html/heincloud/bootstrap/cache/compiled.php(10054): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#38 /var/www/html/heincloud/bootstrap/cache/compiled.php(8356): Illuminate\Pipeline\Pipeline->then(Object(Closure)) 
#39 /var/www/html/heincloud/bootstrap/cache/compiled.php(8347): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request)) 
#40 /var/www/html/heincloud/bootstrap/cache/compiled.php(8338): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) 
#41 /var/www/html/heincloud/bootstrap/cache/compiled.php(2575): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) 
#42 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request)) 
#43 /var/www/html/heincloud/bootstrap/cache/compiled.php(3374): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#44 /var/www/html/heincloud/bootstrap/cache/compiled.php(10069): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#45 /var/www/html/heincloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#46 /var/www/html/heincloud/bootstrap/cache/compiled.php(10054): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#47 /var/www/html/heincloud/bootstrap/cache/compiled.php(2519): Illuminate\Pipeline\Pipeline->then(Object(Closure)) 
#48 /var/www/html/heincloud/bootstrap/cache/compiled.php(2503): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) 
#49 /var/www/html/heincloud/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) 
#50 {main} 

index.blade -> скрипт

@section('after-scripts') 
    {{ Html::script("js/backend/plugin/datatables/jquery.") }} 
    {{ Html::script("js/backend/plugin/datatables/dataTables.bootstrap.min.js") }} 

<script> 
    $(function() { 
     $("#about-table").DataTable({ 
       processing: true, 
       serverSide: true, 
       ajax: { 
        url: '{{ route("admin.about.get") }}', 
        type: 'post', 
        data: {status: 1, trashed: false} 
       }, 
       columns: [ 
        {data: 'id', name: '{{config('access.about_table')}}.id'}, 
        {data: 'title', name: '{{config('access.about_table')}}.title', render: $.fn.dataTable.render.text()}, 
        {data: 'content', name: '{{config('access.about_table')}}.content', render: $.fn.dataTable.render.text()}, 
        {data: 'user_id', name: '{{config('access.about_table')}}.user_id'}, 
        {data: 'actions', name: 'actions', searchable: false, sortable: false} 
       ], 
       order: [[0, "asc"]], 
       searchDelay: 500 
     }); 
    }); 
    </script> 
@stop 

AboutModel

<?php 

namespace App\Aboutpages; 

use Illuminate\Database\Eloquent\Model; 
use App\Aboutpages\Traits\AboutAttribute; 
use Auth; 

class About extends Model 
{ 
    use AboutAttribute; 

    protected $table = "about"; 
    public $fillable = ['title', 'content', 'user_id']; 



    public function __construct(array $attributes = []) 
    { 
     parent::__construct($attributes); 
     $this->table = config('access.about_table'); 
    } 



    protected static function boot() 
    { 
     parent::boot(); 

     static::creating(function ($model) { 
      if (Auth::check()) { 
       $model->user_id = Auth::id(); 
       $model->user_id = Auth::id(); 
      } 
     }); 

     static::updating(function($model) { 
      if (Auth::check()) { 
       $model->user_id = Auth::id(); 
      } 
     }); 
    } 
} 

ManageAboutRequest

<?php 

namespace App\Http\Requests\Backend\About; 

use App\Http\Requests\Request; 

/** 
* Class ManageAboutRequest. 
*/ 
class ManageAboutRequest extends Request 
{ 
    /** 
    * Determine if the user is authorized to make this request. 
    * 
    * @return bool 
    */ 
    public function authorize() 
    { 
     return access()->allow('manage-about'); 
    } 

    /** 
    * Get the validation rules that apply to the request. 
    * 
    * @return array 
    */ 
    public function rules() 
    { 
     return [ 
      // 
     ]; 
    } 
} 

AboutRepository

<?php 

namespace App\Repositories\Backend\About; 

use App\Aboutpages\About; 
use App\Repositories\Repository; 
use Illuminate\Support\Facades\DB; 
use Illuminate\Database\Eloquent\Model; 

/** 
* Class AboutRepository. 
*/ 
class AboutRepository extends Repository 
{ 
    /** 
    * Associated Repository Model. 
    */ 
    const MODEL = About::class; 


    /** 
    * @param string $order_by 
    * @param string $sort 
    * 
    * @return mixed 
    */ 
    public function getForDataTable($order_by = 'sort', $sort = 'asc') 
    { 
     return $this->query() 

      ->orderBy($order_by, $sort) 
      ->select([ 
       config('access.about_table').'.id', 
       config('access.about_table').'.title', 
       config('access.about_table').'.content', 
       config('access.about_table').'.user_id', 
       config('access.about_table').'.sort', 
     ]); 
    } 
} 

AboutTableController

<?php 

namespace App\Http\Controllers\Backend\About; 

use App\Http\Controllers\Controller; 
use Yajra\Datatables\Facades\Datatables; 
use App\Repositories\Backend\About\About\AboutRepository; 
use App\Http\Requests\Backend\About\ManageAboutRequest; 

/** 
* Class AboutTableController. 
*/ 
class AboutTableController extends Controller 
{ 
    /** 
    * @var AboutRepository 
    */ 
    protected $about; 
    /** 
    * @param ManageAboutRequest $request 
    * 
    * @return mixed 
    */ 
    public function __invoke(ManageUserRequest $request) 
    { 
     return Datatables::of($this->about->getForDataTable($request->get('status'), $request->get('trashed'))) 
      ->addColumn('actions', function ($about) { 
       return $about->action_buttons; 
      }) 
      ->withTrashed() 
      ->make(true); 
    } 
} 
+0

Не имеет ни одной идеи или может показать мне более простой способ добавления кнопок действий? –

+0

Вы проверили это: http://stackoverflow.com/questions/25305020/add-an-action-button-based-on-column-value-using-datatable#answers-header –

ответ

0

Потратив несколько часов отладки я мог найти ошибку: D

Я forgott, чтобы получить запрос от функции __construct в AboutTableController. Без этого $ this-> about в строке 26 возвращает null. После этого и несколько модификаций это сработало :)

public function __construct(AboutRepository $abouts) 
{ 
    $this->abouts = $abouts; 
} 

 Смежные вопросы

  • Нет связанных вопросов^_^