Prevent modal duplication for edit in Laravel - laravel-5.3

I'm trying to to editing using bootstrap modals. My problems is that my current way is including the modals in the foreach loop.
#foreach($users as $user)
<tr>
<td align="center"><input type="checkbox" class="i-checks" name="input[]" value="{{ $user->name }}"></td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
{{ $user->role->name }}
</td>
<td>
#if($user->team_id)
{{ $user->team->name }}
#else
{{ 'N/A' }}
#endif
</td>
<td>
#if($user->is_active == 0)
{{ 'Blocked' }}
#elseif($user->is_active == 1)
{{ 'Active' }}
#endif
</td>
<td>
<a data-toggle="modal" href="#modal-edit-{{ $user->id }}"><i class="fa fa-pencil"></i> Edit</a>
</td>
#include('partials.modals.editUser')
</tr>
#endforeach
And my modal looks like this
<div id="modal-edit-{{$user->id}}" class="modal fade" aria-hidden="true" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="col-sm "><h3 class="text-center m-t-none m-b">Edit User</h3>
<form method="POST" action="{{ route('users.update', $user->id )}}">
{{ method_field('PATCH') }}
{{ csrf_field() }}
<div class="form-group"><label>Name</label> <input type="text" placeholder="Enter name" class="form-control" name="name" value="{{ $user->name }}"></div>
<div class="form-group"><label>Email</label> <input type="email" placeholder="Enter email" class="form-control" name="email" value="{{ $user->email }}"></div>
<div class="form-group"><label>Password</label> <input type="password" placeholder="Password" class="form-control" name="password" value="{{ $user->password }}"></div>
<div class="form-group">
<label for="role">Activation</label>
{{ Form::select('activation',
['1' =>'Active',
'0' => 'Blocked',
], $user->is_active, array('class' => 'chosen-select', 'data-placeholder' => 'Choose Activation', 'tab-index' => '4')) }}
</div>
<div class="form-group">
<label for="role">Select Role</label>
{{ Form::select('role',
[1 =>'Admin',
2 => 'Team Leader',
3 => 'Team Member',
], $user->role_id, array('class' => 'chosen-select', 'data-placeholder' => 'Choose a role', 'tab-index' => '4')) }}
</div>
<div class="form-group"><label>Team</label> <input type="text" placeholder="Enter Team" class="form-control" name="team_id" value="{{ $user->team_id }}"> </div>
<input type="submit" class="btn btn-primary btn-rounded btn-block" onclick="pressOnlyOnce()" value="Save Changes">
</div>
</form>
</div>
</div>
</div>
</div>
How can I edit my data using only one modal so that I can place it outside the foreach loop?

You could move the include outside the #foreach loop and add your variables to the button that triggers the modal to use them with javascript.
The button should look like this:
<a data-toggle="modal" href="#modal-edit-{{ $user->id }}" data-user-id="{{ $user->id }}" data-user-active="{{ $user->active }}"><i class="fa fa-pencil"></i> Edit</a>

Related

problem when css/bootstrap/js to my twig template

the login works perfectly fine with the simple form
but when I try to add bootstrap/css/js to it , its doesn't work anymore the
{% if error %}
<span class="error">{{ error.messageKey }} </span>
{% endif %}
shows ( Invalid credentials. ) error!
I just cant find where is the error
Here is the code of the simple form :
<form action=" {{ path ('login') }} " method="POST">
<input type="text" name="_username" value"{{ last_username }}" placeholder="username here.">
<input type="password" name="_password" >
<button type="submit"> login </button>
</form>
here is the code of the form (with css/bootstrap/js)
<form action=" {{ path ('login') }} " method="POST" class="login100-form validate-form">
<div class="login100-form-avatar">
<img src="{{ asset('/logo.jpg') }}" alt="AVATAR">
</div>
<span class="login100-form-title p-t-20 p-b-45">
Bazar-Chic Login page
</span>
<div class="wrap-input100 validate-input m-b-10" data-validate = "Username is required">
<input class="input100" value="{{ last_username }}" type="text" name="_username" placeholder="Username">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-user"></i>
</span>
</div>
<div class="wrap-input100 validate-input m-b-10" data-validate = "Password is required">
<input class="input100" type="password" name="pass" placeholder="Password">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-lock"></i>
</span>
</div>
<div class="container-login100-form-btn p-t-10">
<button class="login100-form-btn">
Login
</button>
</div>
<div class="text-center w-full p-t-25 p-b-230">
<a href="#" class="txt1">
Forgot Username / Password?
</a>
</div>
<div class="text-center w-full">
<a class="txt1" href="http://127.0.0.1:8000/register">
Create an account
<i class="fa fa-long-arrow-right"></i>
</a>
</div>
</form>
As Barbie said the problem was with the name of the input.
(name="pass" => name="_password")
The problem is solved and the topic can be locked!
Thank you ;)
Maybe you should change:
name="pass" to name="_password"

How to Align and Style my View Page in Angular

I am working on a project using Angular-7. I tried to render a modal form with the code shown below:
user.component.html
<div id="addModal" class="modal" style="background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4);">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add New {{ User }}</h5>
<button type="button" class="close" (click)='closeAddModal()'>
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="alert alert-danger" [hidden]="!error.role">
{{ error.role }}
</div>
<div class="alert alert-danger" [hidden]="!error.email">
{{ error.email }}
</div>
<div class="alert alert-danger" [hidden]="!error.first_name">
{{ error.first_name }}
</div>
<div class="alert alert-danger" [hidden]="!error.last_name">
{{ error.last_name }}
</div>
<div class="alert alert-danger" [hidden]="!error.client_id">
{{ error.client_id }}
</div>
<div class="alert alert-danger" [hidden]="!error.password">
{{ error.password }}
</div>
<form #editUserForm=ngForm>
<div class="form-group">
<label for="name">First Name</label>
<input type="name" name="first_name" id="inputName" class="form-control" placeholder="First Name" [(ngModel)]="form.first_name" required>
</div>
<div class="form-group">
<label for="name">Last Name</label>
<input type="name" name="last_name" id="inputName" class="form-control" placeholder="Last Name" [(ngModel)]="form.last_name" required>
</div>
<div class="form-group">
<label for="name">Email</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="example#email.com" required [(ngModel)]="form.email">
</div>
<div class="form-group">
<label for="name">Client</label>
<select class="form-control pt-1" name="client_id" [(ngModel)]="form.client_id">
<option value="null">Select Client</option>
<option *ngFor="let c of clients" value="{{c?.client_id}}">{{c.client_name}}</option>
</select>
</div>
<div class="form-group">
<label for="name">Role</label>
<div *ngFor="let role of roles">
<input type="checkbox" name="{{ role.name }}" value="{{ role.name }}" (change)="checkboxAdd($event)"> {{ role.name }}
</div>
</div>
<div class="form-group">
<label for="name">Password</label>
<input type="password" name="password" id="inputPassword" [(ngModel)]="form.password" class="form-control" placeholder="Password" required>
</div>
<div class="form-group">
<label for="name">Password Confirmation</label>
<input type="password" name="password_confirmation" id="inputPasswordConfirm" [(ngModel)]="form.password_confirmation" class="form-control" placeholder="Re enter Password" required>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)='addModalSubmit()' [disabled]="!editUserForm.valid">Save changes</button>
<button type="button" class="btn btn-secondary" (click)='closeAddModal()'>Close</button>
</div>
</div>
</div>
</div>
In the form, I have checkboxes for user roles. I observed that the form got truncated and some of the checkboxes not being displayed. Also, the submit button is not showing. Even the vertical scrollbar on the page could not resolve the problem.
How do I resolve this and make everything visible?
How do I make the checkboxes to be divided into three (3) columns using:
<div class="col-xs-4">
How do I resolve this and make everything visible?
Using overflow, solve this problem easily. For example;
<div class="content">
this is content * 70
</div>
<style>
.content {
overflow-y: scroll; /* for vertical scroll */
}
</style>
How do I make the checkboxes to be divided into three (3) columns using:
Use flex. Everyting is easy :)
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
<div class="area">
<div *ngFor="let role of roles" class="item">
<input type="checkbox" name="{{ role.name }}" value="{{ role.name }}" (change)="checkboxAdd($event)"> {{ role.name }}
</div>
</div>
<style>
.area {
display: flex;
flex-direction: row;
width: 100%;
}
.area .item {
width: 33.3%;
}
</style>
You could use bootstrap class checkbox-inline to have all the options in one line.
Please Look at this

Laravel 5.6 error "function name must be a string" with builtin Auth

Im trying to modified the builtin laravel Auth to take in more attribute, but have encountered the error "function name must be a string". I didnt know what i did wrong.
Here's my create method:
protected function create(array $data)
{
$imgPath = Storage::putFile('public/photos/users', $data('image'));
$imgPath = 'photos/users/' . basename($imgPath);
return User::create([
'imgPath' => $imgPath,
'firstName' => $data['firstName'],
'lastName' => $data['lastName'],
'about' => $data['about'],
'email' => $data['email'],
'username' => $data['username'],
'password' => Hash::make($data['password']),
'role' => $data['role'],
'province_id' => $data['province_id'],
]);
}
the error show the that the part where i try to store image to $imgPath is where exception occured but i dont know whats wrong there. I used the same code for many time, worked fine. Here's my register view:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="input-group mb-3">
<div class="custom-file">
<label class="custom-file-label" for="image">Upload a picture of yourself</label>
<input type="file" class="custom-file-input" id="image" name="image" required>
</div>
</div>
<div class="form-group row">
<label for="firstName" class="col-md-4 col-form-label text-md-right">{{ __('First Name') }}</label>
<div class="col-md-6">
<input id="firstName" type="text" class="form-control{{ $errors->has('firstName') ? ' is-invalid' : '' }}" name="firstName" value="{{ old('firstName') }}" required autofocus>
#if ($errors->has('firstName'))
<span class="invalid-feedback">
<strong>{{ $errors->first('firstName') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<label for="lastName" class="col-md-4 col-form-label text-md-right">{{ __('Last Name') }}</label>
<div class="col-md-6">
<input id="lastName" type="text" class="form-control{{ $errors->has('lastName') ? ' is-invalid' : '' }}" name="lastName" value="{{ old('lastName') }}" required autofocus>
#if ($errors->has('lastName'))
<span class="invalid-feedback">
<strong>{{ $errors->first('lastName') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<label for="about" class="col-md-4 col-form-label text-md-right">{{ __('About You') }}</label>
<div class="col-md-6">
<textarea placeholder="Tell us something about yourself"
id="about"
name="about"
required autofocus
rows="5" spellcheck="true"
class="form-control{{ $errors->has('about') ? ' is-invalid' : '' }} autosize-target text-left ">{{ old('about') }}</textarea>
#if ($errors->has('about'))
<span class="invalid-feedback">
<strong>{{ $errors->first('about') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required>
#if ($errors->has('email'))
<span class="invalid-feedback">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<label for="username" class="col-md-4 col-form-label text-md-right">{{ __('Username') }}</label>
<div class="col-md-6">
<input id="username" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" name="username" value="{{ old('username') }}" required>
#if ($errors->has('username'))
<span class="invalid-feedback">
<strong>{{ $errors->first('username') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
#if ($errors->has('password'))
<span class="invalid-feedback">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
<input type="hidden" name="role" value="guide" />
<input type="hidden" name="province_id" value="1" />
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
You can change
$data('image')
to
$data['image']
Because $data is an array, not a function.

Delete button is not working in table

This is how my code looks like
'<td class="text-center ">
<form action="/patients/{{$patient->id}}" method="post"
class="delete_link">
{{ csrf_field() }}
{{ method_field(\'DELETE\') }}
<button type="submit" class="btn btn-danger btn-sm pullright">Delete</button>
</form>
</td>'
Remember my table is under single quotations. Someone help me to get this thing working, Please.!!
'<td class="text-center ">
<form action="/patients/{{$patient->id}}" method="post" class="delete_link">
{{ csrf_field() }}
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-danger btn-sm pullright">Delete</button>
</form>
</td>'

can't do normal formating using bootstrap

I am a newbie in laravel and bootstrap. I spent already 2 hours trying to make normal formatting, but the result is
enter image description here
What i'm doing wrong?
<div class="row">
<form method="POST" class="form-inline" action="{{action('OrderController#setDiscont')}}">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="input-group {{ $errors->has('discont') ? ' has-error' : '' }}">
<span class="col-md-7">
<input type="text" placeholder="Скидка" name="discont" class="form-control" value="{{$discont or ""}}">
</span>
<span class="input-group-btn col-md-5">
<input type="submit" value="Установить" class="btn-block btn btn-default" >
</span>
<div class="help-block">
#if ($errors->has('discont'))
<strong>{{ $errors->first('discont') }}</strong> #endif
</div>
</div>
</form>
</div>
<div class="row">
<form method="POST" class="form-inline" action="{{action('OrderController#setClient')}}">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="input-group {{ $errors->has('phone') ? ' has-error' : '' }}">
<span class="col-md-7">
<input type="text" placeholder="телефон" id="phone" name="phone" class="form-control" value="{{ old('phone') }}">
</span>
<span class="input-group-btn col-md-5">
<input type="submit" value="Найти" class="btn btn-primary" >
</span>
<div class="help-block">
#if ($errors->has('phone'))
<strong>{{ $errors->first('phone') }}</strong> #endif
</div>
</div>
</form>
</div>
This should work for you. Read the documentation for input groups. I'm assuming this is what you wanted from your css classes, but you can also check out the documentation for inline forms if that's what you wanted.
<div class="row">
<form method="POST" class="form-inline" action="POST">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="form-group {{ $errors->has('discont') ? ' has-error' : '' }}">
<div class="input-group">
<input type="text" placeholder="Скидка" name="discont" class="form-control" value="{{$discont or ""}}">
<div class="input-group-addon" style="padding:0;">
<input type="submit" value="Установить" class="btn-block btn btn-default" style="border: 0px;border-radius: 0px; background-color: #ddd;">
</div>
</div>
<div class="help-block">
#if ($errors->has('discont'))
<strong>{{ $errors->first('discont') }}</strong>
#endif
</div>
</div>
</form>
</div>
<div class="row">
<form method="POST" class="form-inline" action="POST">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="form-group {{ $errors->has('phone') ? ' has-error' : '' }}">
<div class="input-group">
<input type="text" placeholder="телефон" id="phone" name="phone" class="form-control" value="{{ old('phone') }}">
<div class="input-group-addon" style="padding:0;">
<input type="submit" value="Установить" class="btn-block btn btn-default" style="border: 0px;border-radius: 0px; background-color: #ddd;">
</div>
</div>
<div class="help-block">
#if ($errors->has('phone'))
<strong>{{ $errors->first('phone') }}</strong>
#endif
</div>
</div>
</form>
</div>

Resources