Laravel: Missing argument 1 for AdminController::getUpdateUser() - laravel

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'));

Related

Send Email with multiple images in Laravel9

I'm having problem that I would like to send Email with multiple images in Laravel9.
I wrote below code.
My goal is send Email with multiple images and
sametime each image file name stores into mysql's 'fileattach' column as photo1, photo2, photo3(one line)
Could someone correct my code please?
blade file
<div class="col-sm-6">
<input type="file" name="files[]" accept="file_extension|image/*|media_type" multiple>
</div>
Controller
public function saveContact(Request $request) {
$this->validate($request, [
'name' => 'required',
]);
if(count($files) > 0) {
foreach($files as $file) {
$message->attach($file->getRealPath(), array(
'as' => $file->getClientOriginalName(),custom name
'mime' => $file->getMimeType())
);
}
}
$contact = new Contact($request->all());
$contact->save();
\Mail::send('admin_email_tpl', //admin tpl
array(
'sno' => $request->get('sno'),
'name' => $request->get('name'),
'email' => $request->get('email'),
'files' => $request->post('files'),
), function($message) use ($request)
{
$message->from('123#123foobar.com');
$message->to('123#123foobar.com');
$message->subject('Thank You');
});
You are almost there, need to put the attachment code into callback method to mail.
public function saveContact(Request $request) {
$this->validate($request, [
'name' => 'required',
]);
//Get the $files array here
$files = [];
$contact = new Contact($request->all());
$contact->save();
\Mail::send('admin_email_tpl', //admin tpl
array(
'sno' => $request->get('sno'),
'name' => $request->get('name'),
'email' => $request->get('email'),
'files' => $request->post('files'),
), function($message) use ($request, $files)
{
$message->from('123#123foobar.com');
$message->to('123#123foobar.com');
$message->subject('Thank You');
if(count($files) > 0) {
foreach($files as $file) {
$message->attach($file->getRealPath(), array(
'as' => $file->getClientOriginalName(),//custom name
'mime' => $file->getMimeType())
);
}
}
});
}

syntax error, unexpected token "<" (View: /Users/pathparakh/Projects/store/resources/views/product.blade.php) in laravel?

There are an error showing when i add #if ({{Auth::user()->utype}} == "ADM") Line of code in product.blade.php.
</head>
#if ({{Auth::user()->utype}} == "ADM")
<body>
</body>
#endif
This is my controller named ProductController.
public function index()
{
$products = Product::all();
return view('product', compact('products'));
}
public function create()
{
return view('product');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'brand' => 'required',
'detail' => 'required',
'size' => 'required',
'type' => 'required',
'price' => 'required',
'image' => 'required',
]);
$image = $request->file('image');
$new_name = rand().'.'.$image->getClientOriginalExtension();
$image->move(public_path('images'), $new_name);
$form_data = array(
'image' => $new_name,
'name' => $request->input('name'),
'size' => $request->input('size'),
'type' => $request->input('type'),
'price' => $request->input('price'),
'detail' => $request->input('detail'),
'brand' => $request->input('brand'),
);
Product::create($form_data);
return redirect()->route('product.index')->withSuccess('Done');
}
enter image description here
Please help me to solve the mistake.
You are already using blade directive, so no need to put {{}}, inside #if or any other directive try this
#if (Auth::user()->utype == "ADM")
<body>
</body>
#endif

LARAVEL - Did not update database when submit a form

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)]

how can i use setOpion() and getOption() method in laravel?

i am trying to first set in controller setOption(value, valuename) in controller and store in database and use it as getOption in views
but not working .
Here is my controller =>
public function edit(Request $request)
{
mpc_m_c($request->server('SERVER_NAME'));
$options = Config::all()->pluck('value','name');
$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
return view('admin.system-settings', compact('options', 'tzlist'));
}
public function update(Request $request)
{
$this->validate($request, [
'app_name' => 'required',
'currency_symbol' => 'required',
'currency_code' => 'required',
'date_format' => 'required',
'home_page_description' => 'required',
'recaptcha_private_key' => 'required',
'minimum_deposit_amount' => 'required',
'home_page_meta' => 'required',
'notify_email' => 'required'
]);
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$fileArray = array('logo' => $file);
$rules = array(
'logo' => 'mimes:png|required|' // max 10000kb
);
$validator = Validator::make($fileArray, $rules);
if ($validator->fails()) {
$errors = $validator->errors()->getMessages();
return redirect()
->back()
->withErrors(['logo' => $errors['logo']]);
} else {
$logo = Storage::putFile('images', $request->file('logo'));
setOption('logo', $logo);
}
}
if ($request->hasFile('banner')) {
$file = $request->file('banner');
$fileArray = array('banner' => $file);
$rules = array(
'banner' => 'mimes:png,jpg,jpeg|required|' // max 10000kb
);
$validator = Validator::make($fileArray, $rules);
if ($validator->fails()) {
$errors = $validator->errors()->getMessages();
return redirect()
->back()
->withErrors(['banner' => $errors['banner']]);
} else {
$banner = Storage::putFile('images', $request->file('banner'));
setOption('banner', $banner);
}
}
setOption('app_name', $request->input('app_name'));
setOption('currency_symbol', $request->input('currency_symbol'));
setOption('currency_code', $request->input('currency_code'));
setOption('date_format', $request->input('date_format'));
setOption('home_page_description', $request->input('home_page_description'));
setOption('recaptcha_public_key', $request->input('recaptcha_public_key'));
setOption('recaptcha_private_key', $request->input('recaptcha_private_key'));
setOption('minimum_deposit_amount', $request->input('minimum_deposit_amount'));
setOption('home_page_meta', $request->input('home_page_meta'));
setOption('module_support_enabled', $request->input('module_support_enabled'));
setOption('module_api_enabled', $request->input('module_api_enabled'));
setOption('module_subscription_enabled', $request->input('module_subscription_enabled'));
setOption('theme_color', $request->input('theme_color'));
setOption('background_color', $request->input('background_color'));
setOption('language', $request->input('language'));
setOption('display_price_per', $request->input('display_price_per'));
setOption('admin_layout', $request->input('admin_layout'));
setOption('user_layout', $request->input('user_layout'));
setOption('panel_theme', $request->input('panel_theme'));
setOption('anonymizer', $request->input('anonymizer'));
setOption('front_page', $request->input('front_page'));
setOption('show_service_list_without_login', $request->input('show_service_list_without_login'));
setOption('notify_email', $request->input('notify_email'));
setOption('currency_separator', $request->input('currency_separator'));
setOption('timezone', $request->input('timezone'));
Session::flash('alert', __('messages.updated_logout_needed'));
Session::flash('alertClass', 'success');
return redirect('/admin/system/settings');
}
route =>
Route::get('/system/settings', 'ConfigController#edit');
Route::put('/system/settings', 'ConfigController#update');
error =>
"Call to undefined function App\Http\Controllers\Admin\setOption()"
and view =>
<div class="form-group{{ $errors->has('home_page_meta') ? ' has-error' : '' }}">
<label for="home_page_meta" class="control-label">meta tags</label>
<textarea
style="height: 150px;"
class="form-control"
data-validation="required"
rows="5"
id="home_page_meta"
name="home_page_meta"> <?php echo e($options['home_page_meta']) ?></textarea>
</div>
use =>
getOption('valuename')
And by this things he is using the function getOption(''valuename) anywhere in the entire application ... i really dont want use it but just curious How he is using this things even there's no laravel build in funtion for this name?
*Note : Please don't judge me , I just want to know ..thnaks
anybody got idea how do i use it ?

Profile page for logged user - laravel 5.2

The problem is, when i submit the form, the browser throw MethodNotAllowedHttpException in RouteCollection.php line 219:
My route
Route::group(['middleware' => ['web']], function () {
Route::resource('dash/reports', 'Dash\\ReportsController');
});
/* ruote for Admin */
Route::group(['middleware' => ['role:admin']], function () {
Route::resource('dash/categories', 'Dash\\CategoriesController');
});
Route::group(['middleware' => ['role:admin']], function () {
Route::resource('dash/roles', 'Dash\\RolesController');
});
Route::group(['middleware' => ['role:admin']], function () {
Route::resource('dash/permissions', 'Dash\\PermissionsController');
});
Route::group(['middleware' => ['role:admin']], function () {
Route::resource('dash/users', 'Dash\\UsersController');
});
/* another routes */
Route::auth();
Route::get('/profile-edit/{id}', 'Dash\\UsersController#editUser');
My controller:
public function editUser($id)
{
$auth = Auth::user()->id;
$user = User::findOrFail($id);
if($auth == $user->id){
return view('dash.users.update_profile', compact('user'));
}
return redirect('errors/404');
}
public function storeUpdatedUser($id, Request $request)
{
$this->validate($request, ['email' => 'required', 'name' => 'required', 'password' => 'required', 'surname' => 'required', ]);
$user = User::findOrFail($id);
$user->update($request->all());
$user->password = bcrypt($request->password);
$user->save();
Session::flash('flash_message', 'User updated!');
return redirect('/');
}
the view:
{!! Form::model($user, [
'method' => 'PATCH',
'url' => ['/profile-edit', $user->id],
'class' => 'form-horizontal'
]) !!}
........
WHere is the problem? And another problem is the field "password" show me a hased password, anyone can explaine me ?
You are sending a PATCH request to a get route:
Route::get('/profile-edit/{id}', 'Dash\\UsersController#editUser');
{!! Form::model($user, [
'method' => 'PATCH',
'url' => ['/profile-edit', $user->id],
'class' => 'form-horizontal'
]) !!}
Change the route from get to patch
Route::patch('/profile-edit/{id}', 'Dash\\UsersController#editUser');
Try to use Route::put('/profile-edit/{id}'...
solved:
Route::get('/profile-edit/{id}/edit', 'Dash\\UsersController#editUser');
Route::patch('/profile-edit/{id}', 'Dash\\UsersController#storeUpdatedUser');

Resources