I'm trying to send two arguments and one request to controller with post request. This is the code where I send the arguments:
<form class="form-horizontal" name="form1" method="post" action="{{ route('shipment_view', $uniqueid, $category_name) }}" role="form" enctype="multipart/form-data">
And this is the controller where I'm sending the arguments:
public function storeShipment(Request $request, $number, $category_name){
$category = Category::where('category_name', $category_name)->first();
$user = Auth::user();
$item = new Item([
'id' => $user->id,
'category_id' => $category->id,
'unq' => $number,
'fullname' => $request->input('name'),
]);
$item->save();
}
But when I open the view it gives me error
ErrorException in NewShipmentController.php line 53:
Missing argument 3 for App\Http\Controllers\NewShipmentController::storeShipment()
Update:
My route function:
Route::post('/ship/preview/{number}',[
'uses' => 'Controllerr#storeShipment',
'as' => 'shipment_view'
]);
Any ideas?
replace your route function with the below one
Route::post('/ship/preview/{number}/{category_name}',[
'uses' => 'Controllerr#storeShipment',
'as' => 'shipment_view'
]);
Hope this solves your problem.
You can get the all the parameters through request it self But before this how you are defining the route
public function storeShipment(Request $request){
$number = $request->number;
$category_name = $request->number
}
Related
I have create a validation request file on request folder. It working fine in new insert. But when i update, it's not working also i pass the unique $id but not working.
a. Resource controller update method
public function update(KlassNameRequest $request, $id)
{
$validated = $request->validated();
KlassName::where('id', $id)->update($validated);
}
b. Validation code
public function rules()
{
return [
'name' => 'required|unique:klass_names|max:128,' . $this->id,
'ref' => 'required|unique:klass_names|numeric|between:1,999,' . $this->id,
'seat_quota' => 'required|numeric|between:1,9999',
'division' => 'required',
'semester' => 'required',
];
}
This message shows me when i update
return [
'name' => 'required|unique:klass_names,' . $this->id.'|max:128',
'ref' => 'required|unique:klass_names,' . $this->id.'|numeric|between:1,999',
'seat_quota' => 'required|numeric|between:1,9999',
'division' => 'required',
'semester' => 'required',
];
Just try this one
'name' => ['required','max:128',Rule::unique('klass_names')->where(function ($query) {
return $query->where('name', $this->name);
})],
'ref' => ['required','max:128',Rule::unique('klass_names')->where(function ($query) {
return $query->where('ref', $this-> ref);
})],
Hope it will solve the problem 😊
I have solve my problem in this way -
a. Add extra input hidden field passing id for $request method. Because my route is resource group route -
<form action="{{ route('adm.kls.update', $kls->id) }}" method="post">
#csrf
#method('PUT')
<input type="hidden" name="id" value="{{ $kls->id }}">
</form>
b. Some editing in validation code.
public function rules() {
return [
'name' => 'required|max:128|unique:klass_names,name,' . $this->id,
'ref' => 'required|numeric|between:1,999|unique:klass_names,ref,' . $this->id,
'seat_quota' => 'required|numeric|between:1,9999',
];
}
done.
When pressed the submit button nothing happens and did not update database. Please help me.
Controller:
public function update(Request $request, $id)
{
$this->validate(request(), [
'name' => 'required',
'email' => 'required|email|unique:users',
]);
//$user = Auth::user();
$user = user::where('id',$id)->update($request->except('_token','_method'));
$user->name = request('name');
$user->email = request('email');
$user->password = bcrypt(request('password'));
$user->firstname = $request->firstname;
$user->middlename = $request->middlename;
$user->lastname = $request->lastname;
$user->birthday = $request->birthday;
$user->nationality = $request->nationality;
$user->gender = $request->gender;
$user->civilstatus = $request->name;
$user->mobilenum = $request->mobilenum;
$user->worknum = $request->worknun;
$user->workadd = $request->workadd;
$user->homeadd = $request->homeadd;
$user->email = $request->email;
$user->save();
return redirect(route('user.user.show'))->with('message','Announcement Updated Succesfully');;
}
edit.blade.php
<form method="POST" action="{{ route('user.user.update', $user->id)}}">
{{ csrf_field() }}
{{ method_field('PATCH') }}
..
..
..
<button type="submit" class="btn btn-primary">Submit</button>
Back
Routes
Route::get('users/{user}', ['as' => 'user.user.show', 'uses' => 'UserController#index']);
Route::get('users/edit/{user}', ['as' => 'user.user.edit', 'uses' => 'UserController#edit']);
Route::PATCH('users/update/{users}', ['as' => 'user.user.update', 'uses' => 'UserController#update']);
Please help me. Thank you in advance!
From what i can see i think you're $request is not passing the unique validation on email.
since it's an update function leaving unique fields in a form (e.g. email - username) unchanged will result in a validation error try to bypass it with this:
'email' => ['required','email',Rule::unique('users')->ignore($id)]
I'm tryng to built a controller for a newsletter, her is my code:
Controller
public function postNews(Request $request, $user) {
$this->validate($request, [ 'email' => 'required | email' ]);
$user = User::findOrFail($id);
$data = array(
'email' => $request->email);
$token = $request->input('g-recaptcha-response');
if (strlen($token) > 0 ) {
Mail::send('emails.newsletter', $data, function( $message ) use ($data) {
$message->from($data['email']);
$message->to($user->email, $user->name)->subject('A-Studio News Letter');
//$message->subject($data['subject']);
});
Session::flash('success', 'Grazie per esserti iscritto alla nostra news letter!');
return view('blog.posts')->withPosts($posts);
}else {
return view('pages.nobot');
}
}
Route
Route::post('posts/{user}', ['uses' => 'BlogController#postNews', 'as' => 'blog.posts']);
Response
MethodNotAllowedHttpException in RouteCollection.php line 218:
Any idea?
Thank you.
<form method="post" action="/posts">
<input name="email" type="email">
<button type="submit">subscribe</button>
</form>
Route::post('/posts', 'YourController#userSubscribe');
public function userSubscribe(Request $request){
$data = $request->input('email');
//Validate $data if necessary and save in the DB
}
This should work.
You should remove the,
Route::post('posts/{user}', '....');
use as,
Route::post('posts', '....');
And also use the controller function with $user variable in the parameters.
I hope this will help you.
You should make POST request
<form action="posts/{{user}}" method="POST">
I'm new to larevel and i've been trying to solve this problem starting yesterday up to now and haven't make any progress and im stuck here....
PLEASE HELP :(
Here's my code for the routes:
Route::get('/admin/edit', array('uses' => 'AdminController#getUpdateUser', 'as' => 'getUpdateUser'));
Route::resource('admin1', 'AdminController');
Here's my code for the button viewing the update (I think the problem might be here and i cant think of a code that will call the id D: )
{{ link_to_action('AdminController#getUpdateUser', 'Edit', array($users->id),array('class' => 'btn btn-info')) }}
--
Here's my code at my AdminController:
public function getUpdateUser($id)
{
$users = User::find($id);
//load view and pass users
return View::make('admin.edit')
->with('users', $users);
}
public function updateUser($id)
{
$validate = Validator::make(Input::all(), array(
'firstname' => 'required',
'lastname' => 'required',
'middlename' => 'required',
'address' => 'required',
'birthday' => 'required',
'contact' => 'required|numeric',
'email' => 'required'
));
if ($validate->fails()) {
return Redirect::to('admin.edit')
->withErrors($validate)
->withInput(Input::except('password'));
}
else
{
$user = User::find($id);
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->middlename = Input::get('middlename');
$user->address = Input::get('address');
$user->birthday = Input::get('birthday');
$user->contact = Input::get('contact');
$user->email = Input::get('email');
if($user->save())
{
return Redirect::route('admin.view')->with('success', 'USER HAS BEEN UPDATED');
}
else
{
return Redirect::route('admin.view')->with('fail', 'An error occured while updating the user. Please double check your inputs and try again.');
}
}
}
Here's my code for admin.edit
#extends('layouts.master')
#section('head')
#parent
<title>Manage Users</title>
#stop
#section('content')
<div class ="container">
<h1>Edit User</h1>
{{ Form::model($users, array('route' => array('admin1.updateUser', $users- >id), 'method' => 'PUT')) }}
--textboxes and inputs here--
{{ Form::submit('Update', array('class' => 'btn btn-info')) }}
Please help me T_T THANK YOU!!!
What you missed is putting the id actually in the route URL as a route parameter. Like this:
Route::get('/admin/edit/{id}', array('uses' => 'AdminController#getUpdateUser', 'as' => 'getUpdateUser'));
I have a registration form and it was working until it just didn't. I am sure I did something with the code because I am new to laravel 4 so I am unable to identify my wrong doing. Now I am getting
This webpage has a redirect loop.
This is the route file:
Route::get('/','MainController#index');
Route::get('/login', 'MembersController#login');
Route::get('/signup', 'MembersController#signup');
/*handled by controller to register the user that signed up*/
Route::get('/register', 'MembersController#register');
/* Handle authenticating a user when loggin in*/
Route::post('register', array(
'uses' => 'MembersController#register',
'as' => 'members.register'
));
and this is the form opening:
#section('content')
{{ Form::open(array('route' => 'members.register')) }}
......
{{ Form::close() }}
#stop
and this is the validation where if there is an error, it used to redirect to the sign-up page again and show them (and it did until it broke)
public function register()
{
$rules = array(
# place-holder for validation rules
'firstname' => 'Required|Min:3|Max:40|Alpha',
'lastname' => 'Required|Min:3|Max:40|Alpha',
'email' => 'Required|Between:3,64|Email|Unique:users',
'country' => 'Required',
'password' =>'Required|AlphaNum|Between:7,15|Confirmed',
'password_confirmation'=>'Required|AlphaNum|Between:7,15'
);
/*Create new user if no user with entered email exists. Use validator to ensure all fields are completed*/
$user = new User;
$validator = $this->validate(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::to('register')->withErrors($validator);
}else{
echo "Success";
}
}
Thanks for the help :)
Change the following line
return Redirect::to('register')->withErrors($validator);
with this
return Redirect::back()->withInput()->withErrors($validator);
You are calling the route register infinite times.
Remove this route as well. You only need post route.
/*handled by controller to register the user that signed up*/
Route::get('/register', 'MembersController#register');