takielias / tablar

Tablar: A Laravel Dashboard Preset Based on Tabler HTML Template + Vite. https://tablar.ebuz.xyz/docs
https://tablar.ebuz.xyz
MIT License
272 stars 33 forks source link

Attempt to read property "name" on null #41

Closed juanla closed 7 months ago

juanla commented 7 months ago

Hello!

I just installed Tablar on a fresh laravel 10.x project. This project was empty except my Model classes. Looks like all default behaivour is working (login redirect, register, etc..)

Anyway, I want work with a public page, then created a "test.blade.php" with the example snippet in my views directory.

@extends('tablar::page')
@section('content')
    <!-- Page header -->
    <div class="page-header d-print-none">
        <div class="container-xl">
            <div class="row g-2 align-items-center">
                <div class="col">
                    <h2 class="page-title">
                        Empty page
                    </h2>
                </div>
            </div>
        </div>
    </div>
    <!-- Page body -->
    <div class="page-body">
        <div class="container-xl">
            @if(config('tablar','display_alert'))
                @include('tablar::common.alert')
            @endif
            <!-- Page Content goes here -->
        </div>
    </div>
@endsection

I have my HomeController with the next content:

use Illuminate\Http\Request;

class HomeController extends Controller
{
    public function __construct()
    {
        /*
         $this
            ->middleware('auth')
            ->except(['index']);
        */
    }
    public function index()
    {
        return view('test');
    }
}

And my web.php file with this content:

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;

Auth::routes();

Route::get('/',
    [HomeController::class, 'index']
);

Route::get('/home',
    [HomeController::class, 'index']
);

When I try enter on my homeController route I get this error: Attempt to read property "name" on null

this error point in the "@endsection" line on my test.blade.php

I am missing some to config to use this page? When I sign in the app with a user, the template works fine. Maybe it's at the time loading my username on the navbar or something. Can I use this tablar to add some public pages?

takielias commented 7 months ago

@juanla @extends('tablar::page') was designed to work only with Auth users. Did you get this error before login?

juanla commented 7 months ago

Yes, the error only happens when I am not logged :)

I though that I can make some public pages with this package, my fault! Thanks a lot for the quick help @takielias