thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.72k stars 2.67k forks source link

Passing variable to view #5848

Open admiralmedia opened 3 months ago

admiralmedia commented 3 months ago

Laravel version

9.52.16

PHP version

8.3.3-1+0~20240216.17+debian10~1.gbp87e37b

Voyager version

1.7

Database

MariaDB version 10.3.39

Description

I'm trying to pass information from 2 tables to the overriten read.blade.php(resources/views/vendor/voyager/pacient/read.blade.php) of my PacientsController but I can't figure out why I get Undefined variable $pacient error . Everything I put into the Controller is not passed to the view. I have the following controller: <?php namespace App\Http\Controllers; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; use App\Pacients; class PacientsController extends Controller { public function read($id) { $pacient = Pacients::with('details', 'profile')->findOrFail($id); return view('pacients.read')->with($pacient); } } I have the following route: Route::get('/pacients/{id}', 'PacientsController@read')->name('pacients.read');

I have the following model: <?php namespace App; use Illuminate\Database\Eloquent\Model; class Pacients extends Model { protected $table = 'pacients'; public function details() { return $this->hasOne(details::class, 'pacient_code', 'id'); } public function profile() { return $this->hasOne(Profile::class, pacient_code', 'id'); } }

I have the following view: {{ dd($pacient); }}

Steps to reproduce

As described

Expected behavior

Show the informations

Screenshots

No response

Additional context

No response