Missing argument 2 in Laravel Controller - laravel-5.3

I am trying to log a user in and take them to a page that displays content based on a slug.
I get this error :
ErrorException in ApplicantLoginController.php line 21:
Missing argument 2 for App\Http\Controllers\Auth\ApplicantLoginController::Login()
This is my controller :
public function Login(Request $request, $slug){
//Validate the form
$this->validate($request, [
'email' => 'required',
'password' => 'required',
'agree' => 'required'
]);
//Attempt to log the user in
if (Auth::guard('applicant')->attempt(['email' => $request->email,'password' => $request->password] )) {
$house = House::where('slug', '=', $slug)->first();
return view('client.index')->withHouse($house);
}
return redirect()->back()->withInput($request->only('email'));
}
This is the route to the page I am taking them to after login :
Route::get('client/index/{slug}', ['as' => 'client.index', 'uses' => 'ClientRegistrationController#index']);
This are my login routes :
Route::get('client/login', 'Auth\ApplicantLoginController#ShowLoginForm')->name('client.login');
Route::post('/client/login', 'Auth\ApplicantLoginController#Login')->name('client.login.submit');
Any ideas on how I can solve this problem?
This the button that takes the user to the page with the content based on a slug
Book now
If the user is not logged in the page redirects to this login page:
<form class="form-horizontal" role="form" method="POST" action="{{ route('client.login.submit') }}">
<input name="_token" type="hidden" value="{{ csrf_token()}}"/>
<div class="form-group">
<label for="email" class="col-md-3 control-label"></label>
<div class="col-md-6">
<input type="email" class="form-control" placeholder="Your Email" name="email" required="">
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-3 control-label"></label>
<div class="col-md-6">
<input type="password" class="form-control" placeholder="Password" name="password" required="">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="agree" required=""> I have read and accepted the terms and condition
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-3">
<input type="submit" value="Login" class="btn btn-primary">
</input>
<a class="btn btn-link" href="#">
Forgot Your Password?
</a>
</div>
</div>
</form>

You should have $slug declared in the post route:
Route::post('/client/login/{slug}', 'Auth\ApplicantLoginController#Login')->name('client.login.submit');
And change your form to add the parameter:
<form class="form-horizontal" role="form" method="POST" action="{{ route('client.login.submit', ['slug' => $slug]) }}">

Related

how to pass data from bootstrap form to mockemployeerepo in asp .net core razor pages

<div class="form-group row">
<label asp-for="EmployeeEditProperty.Name" class="col-sm-2 col-form-label">
</label>
<div class="col-sm-10">
<input asp-for="EmployeeEditProperty.Name" class="form-control" placeholder="Name">
</div>
</div>
<div class="form-group row">
<label asp-for="EmployeeEditProperty.Email" class="col-sm-2 col-form-label"></label>
<div class="col-sm-10">
<input asp-for="EmployeeEditProperty.Email" class="form-control" placeholder="Email">
</div>
</div>
Data not passing to
Employee employee= _EmployeeList.FirstOrDefault(e => e.ID == UpdatedEmployee.ID);
if(employee !=null)
{
employee.Name = UpdatedEmployee.Name;
employee.Email = UpdatedEmployee.Email;
employee.Department = UpdatedEmployee.Department;
}
The properties in view should match the property name in your post action,
You can check my demo:
<form method="post">
<div class="form-group row">
<input hidden asp-for="EmployeeEditProperty.ID" value="1" />
</div>
<div class="form-group row">
<label asp-for="EmployeeEditProperty.Name" class="col-sm-2 col-form-label">
</label>
<div class="col-sm-10">
<input asp-for="EmployeeEditProperty.Name" class="form-control" placeholder="Name">
</div>
</div>
//....
<input type="submit" value="Submit" />
The property names EmployeeEditProperty, so in post method, it should be EmployeeEditProperty too:
public ******(Employee EmployeeEditProperty)
Result:
Model Binding in razor pages, you can check this article

how to insert multiple field data in one column in database in laravel

I want to play with this fields,i want to insert description1,description2 data into this description[] how to do that i tried but something is missing.
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description[]" placeholder="Enter description">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description 1 (optional)</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description2" placeholder="Enter description">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description 2 (optional)</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description3" placeholder="Enter description">
</div>
</div>
public function store(Request $request)
{
$description1 = $request->input('description1');
$description2 = $request->input('description2');
$products = new ProductAdd;
$prodduct->name = $request('name');
$prodduct->description[] = [
'description1' => $description1;
'description2' => $description2;
];
$product->save();
}
If you cast the description field to be an array in your model, you can update your controller code to:
$prodduct->description = [
'description1' => $description1;
'description2' => $description2;
];
To cast the field to an array, add this to your ProductAdd Model:
$casts = [
'description' => 'array'
];

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.

how to get data by finding all and finding one at the same time

In my project on the user edit page I would like to show the current role,wich i get by findOne byId,but I would also like to get all available roles so that I can choose, roles are in a separate collection, and I dont have a problem when displaying eather one...or all..
<div class="form-group col-lg-12">
<label>Email</label>
<input type="email" class="form-control" id="email" value="{{emails.[0].address}}">
</div>
<div class="form-group col-lg-12">
<label>Password</label>
<input type="password" name="" class="form-control" id="password" value="{{password}}">
</div>
<div class="form-group col-lg-6">
<label>Name</label>
<input type="text" name="" class="form-control" id="firstname" value="{{profile.name}}">
</div>
<div class="col-xs-12"><strong>Current role:</strong>
<label class="radio-inline">
<input type="radio" name="optradio" id="accountRole" value="{{roleName profile.role}}" checked>{{roleName profile.role}}
</label>
</div>
{{/with}}
<div class="col-xs-12">
<form>
<div class="col-xs-12"><strong>Roles:</strong>
{{#each rolesInformation}}
<label class="radio-inline">
<input type="radio" name="optradio" id="accountRole" value="{{_id}}">{{roleName}}
</label>
{{/each}}</div>`
helpers look like this:
Template.editUser2.helpers({
user: () => {
return Meteor.users.findOne({_id:Session.get('id')});
},
playerInformation: () => {
return Players.find().fetch();
},
roleName: (id)=>{
return Roles.findOne({_id:id}).roleName;
},
rolesInformation: () =>{
return Roles.find().fetch();
},
when i run roleName or rolesInformation separateli it works fine...
whet both included i get "roleName not defined"

Thymeleaf checkbox not passing value to controller

<form class="form-horizontal" action="#" data-th-action="#{/admin/role/permission/save}" data-th-object="${permission}" method="post">
<div class="form-group">
<label class="col-sm-5 control-label" data-th-text="#{permission.list.permission.label}">Permission</label>
<div class="col-sm-7">
<input type="text" hidden="hidden" data-th-value="*{id}" data-th-field="*{id}" ></input>
<input type="text" class="form-control" data-th-value="*{permissionname}" data-th-field="*{permissionname}" ></input>
</div>
</div>
<div class="form-group" th:each="role : ${allRoles} ">
<label class="col-sm-5 control-label" data-th-text="${role.rolename}">Role 1</label>
<div class="col-sm-7">
<input type="checkbox" th:field="*{permRoles}" th:value="${role}"></input>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-5 col-sm-7" >
<button type="submit" class="btn btn-primary" name="action"
data-th-value="#{button.action.save}" data-th-text="#{button.label.save}" >Save</button>
<button type="submit" class="btn btn-default active" name="action"
data-th-value="#{button.action.cancel}" data-th-text="#{button.label.cancel}">Cancel</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-5 col-sm-7" >
<p class="text-danger" data-th-if="${#fields.hasErrors('permissionname')}"
data-th-errors="*{permissionname}">type error</p>
</div>
</div>
</form>enter code here
above is the html code , I have a permission object, and wants to assign list of roles to it by using the checkbox, the pass the object back to controller. But the value is not assigned to permission.permroles.
#RequestMapping(value = "/save", method = RequestMethod.POST)
#PreAuthorize("hasRole('PERMISSION_SAVEORADD')")
public ModelAndView savePermission(#ModelAttribute Permission permission, BindingResult result)
throws PermissionNotFoundException {
System.out.println(permission.getPermRoles().size());
permissionDao.updatePermission(permission);
return new ModelAndView("redirect:/admin/role/permission/list");
}
The above is my controller
please help, i am stuck for days.
thank you in advance
I think you could try to solve your problem using hidden input with underscore prefix.
<form th:action="#{${flowExecutionUrl}(_eventId='change')}" th:method="post">
<input type="hidden" name="_fooBar" th:value="${fooBar}"/>
<input type="checkbox" id="fooBar" name="fooBar" th:checked="${fooBar}" />
<!-- rest of code ommited -->
</form>
I had simmilar issue, see my blog post http://lukasgrygar.com/thymeleaf/thymeleaf-tips-and-tricks/#fix-of-problem-with-unchecked-checbox-when-using-thymeleaf-and-spring-web-flow

Resources