lundi 7 mars 2016

View share in Laravel 5

I have this class and $total_mess variable to count the message that user haven't read. I have the problem that no matter if the user is logged in or not I just receive $total_mess with an empty string (for second if condition).

<?php namespace App\Providers;

use App\Chat;
use Auth;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider {

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot() {
        if (Auth::check()) {
            $total_mess = Chat::whereRaw('view = ?  and  to_user = ?', [0, Auth::user()->username])->count();
            view()->share('total_mess', $total_mess);
        }
        if (Auth::guest()) {
            view()->share('total_mess', '');
        }
    }

So how can I solve this issue?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire