vendredi 16 novembre 2018

Display table data without user auth

I'm studying event message board. I can display table data by every Users own post. however I would like to display All post too. I wrote this as $tasksall but it didn't work. Could someone teach me what is wrong?

AController.php

public function index()
{

    $tasks = Auth::user()
        ->tasks()
        ->orderBy('is_complete')
        ->orderByDesc('created_at')
        ->paginate(5);

    $tasksall =
        ->tasks()
        ->orderBy('is_complete')
        ->orderByDesc('created_at')
        ->paginate(5);

    return view('tasks', [
        'tasks' => $tasks, 'tasksall' => $tasksall
    ]);
}

Task.php (model)

class Task extends Model
{

    protected $casts = [
        'is_complete' => 'boolean',
    ];


    protected $fillable = [
        'title',
        'is_complete',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire