[SOLVED] I have a simple listing in my laravel 5.7 project,and used voyager to manage its data. and i want to make a fully working created_by and last_edit_by BREAD table but still have no idea to get the currently logged in user.
i currently using custom views(resources/views/vendor/voyager) with copy-pasted original codes,but still using original VoyagerBreadController.php with some additional import.
?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Auth\AuthManager;
use Illuminate\Support\Facades\Auth;
use Auth\Illuminate\Foundation\Auth\AuthenticatesUsers;
use App\Wisata;
use App\User;
namespace App\Http\Controllers\Voyager;
use TCG\Voyager\Http\Controllers\VoyagerBreadController as BaseVoyagerBreadController;
class VoyagerBreadController extends BaseVoyagerBreadController
{
//
}
and able to do this on my custom view
//get currently logged user
@php
$currentUser = Auth::user()->nama;
@endphp
//printed output(for testing)
{{$currentUser}}
and it works!,so i tried to set the BREAD option like this
{
"default" : "{{$currentUser}}"
}
however,unlike my custom views it doesn't returned the $currentUser value,just plain {{$currentUser}} in my tables.
please help me to make a fully functional created_by and last_edit_by table.
notes: im open to use any packages.
EDIT : it's solved by duplicating the form just below the real dynamic form in my custom view(edit-add.blade.php),make a hidden type created_by & last_edited_by table & keep the BREAD option empty. and you can still adjust the visiblity without any problems.
//created_by form
<div class="form-group hidden col-md-12 "><input type="hidden" class="form-control" name="created_by" placeholder="Created By" value="{{$currentUser}}"></div>
//last_edited_by form
<div class="form-group hidden col-md-12 "><input type="hidden" class="form-control" name="last_edited_by" placeholder="Last Edited By" value="{{$currentUser}}"></div>
anyway , i still would be very thankful if someone give more efficient solution :)