I made a package which is counting the visitors on a webpage. Currently I have a single route, controller and view which don't do very much other than display a simple string. I have a separate Laravel application where this package is specifically build for. In this separate application I have a layout file called backend.
layouts/layouts/backend.blade.php
.
My package view is extending this template like so: (backend.blade.php does not exists in the package but in the separate laravel application of-course)
@extends('layouts.layouts.backend')
@section('content')
<div class="container-fluid pt-5 ">
<div class="row">
<div class="col-md-6">
<h3></h3>
</div>
</div>
</div>
@endsection
The package successfully extends this layout but it can't find functions such as Auth::user()->token
and it will say
Trying to get property 'token' of non-object (View: /Users/rainierlaan/Sites/rainierlaan/resources/views/layouts/layouts/backend.blade.php)
Why does this happen?
This is my packages service provider
public function register()
{
// Controllers
$this->app->make('Rainieren\Visitors\Http\Controllers\VisitorController');
// Views
$this->loadViewsFrom(__DIR__.'/resources/views', 'visitors');
$this->publishes([
__DIR__.'/resources/views' => resource_path('views/visitors'),
]);
// Migrations
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
include __DIR__ . '/routes/routes.php';
}
When I do vendor:publish
the view successfully publishes to the right folder but somehow can't recognise functions such as Auth::user()->token
or Auth::user()->unreadNotifications->count())
This is my package route:
<?php
Route::get('dashboard/visitors', '\Rainieren\Visitors\Http\Controllers\VisitorController@index')->name('visitors');
And this is the controller
public function index()
{
return view('visitors::index');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire