Laravel Tips: Load Function from Controller on Blade



Indonesia
English
Saya memiliki fungsi di controller yang akan digunakan di blade dengan cara seperti ini. Saya buat fungsi dulu di controller, contoh seperti ini:
public function getUser($id){
        $user = User::find($id);
        return $user;
    }
Selanjutnya saya menggunakan ini di bagian blade:
@php $user = app('Modules\ClientManagement\app\Http\Controllers\ClientController')->getUser($client->assigned_to); echo $user->name; @endphp

Sangat sederhana bukan? Silahkan kalau bermanfaat di chare atau disimpan sebagai catatan pribadi.

I have a function in the controller that will be used in the blade like this. First, I create the function in the controller, for example like this:
public function getUser($id){
        $user = User::find($id);
        return $user;
    }
Next, I use this in the blade:
@php $user = app('Modules\ClientManagement\app\Http\Controllers\ClientController')->getUser($client->assigned_to); echo $user->name; @endphp

It's pretty simple, isn't it? Feel free to use it or save it as a personal note if it's helpful.

Please Select Embedded Mode To Show The Comment System.*

Lebih baru Lebih lama

Ads

Free Hosting

Hottest Hosting

Niagahoster-Banner