How can I use same view file for different role types in Laravel 7?

I am creating a module to ToDo list. If the role type is admin, she/he can assign ToDo to any user. However, if a normal user creates a ToDo, it will automatically, be assigned to current user. I implemented like below:

ToDoController function looks like below:

public function create()
{

return view('todo.create',['countries' => Country::all(), 'business_types' => BusinessType::all(), 'users' => User::all()]);
}

The view file create.blade.php with user selection select box is as below:

            @if(!empty(Auth::user()->roles()->where('name','admin')->first()))
<div class="form-group">
<label for="description">Assigned To</label>
<select class="form-control" name="user_id">
@foreach ($users as $user)
@if ($user->id == old('user_id'))
<option value="" selected></option>
@else
<option value=""></option>
@endif
@endforeach
</select>
@if ($errors->has('user_id'))
<div class="alert-danger">
<p></p>
</div>
@endif
</div>
@else
<div class="form-group" style="display:none;">
<label for="description">Assigned To</label>
<select class="form-control" name="user_id">
<option value="" selected></option>
</select>
@if ($errors->has('user_id'))
<div class="alert-danger">
<p></p>
</div>
@endif
</div>
@endif

In the case of normal user, it is not required to take all users value, but I can’t avoid that. Is there any optimized method to implement the same this ?

Thanks in Advance ! Manu

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/2Kq0Rru
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.