How to store data in a database using laravel
Please what is wrong with this code…am a newbie and this task was given to complete, I watch YouTube and read online but I can seem to figure out how to store records in database …
This is UserController
namespace AppHttpControllers; use IlluminateHttpRequest; use
Storage; use AppUser;class UserController extends Controller {
/**
* @return $this
*/
public function showUsersWithProperty() {$users = User::all()->filter(function($user) { return $user->properties->count(); }); return view('settings.manageusers') ->with('users', $users); } public function editUser(Request $request, $id){ $users = User::all()->filter(function($user) { return $user->properties->count(); }); $user = User::find($id); return view('settings.manageusers') ->with('users', $users)->with('editId', $user->id); } public function updateUser(Request $request, $id){ $input = $request; $user = User::find($input->id); if ($input->hasFile('userPic')) { $image = $input->file('userPic'); $realname = pathinfo($input->file('userPic')->getClientOriginalName(),
PATHINFO_FILENAME);
$extension = $image->getClientOriginalExtension();
$new_name = time().”.”.$extension;
$image->storeAs(‘public/uploads’, $new_name);
$path = Storage::url(“uploads/” . $new_name);
$user->image_url = $path;
}$user->first_name = $input->fname; $user->last_name = $input->lname; $user->pin = $input->changePin; if($input->deactivate =="on" || $input->deleteUser =="on"){ $user->account_status = 0; } else { $user->account_status = 1; } $user->save(); return redirect()->route('manageUsers')->with('status', "User Updated"); } }
This my Route
Route::post(‘/settings/updateUser/’,
‘UserController@updateUser’)->name(“user.update”);
Route::get(‘/settings/updateUser/’,
‘UserController@updateUser’)->name(“user.update”);
from Laravel Questions and Answers https://laravelquestions.com/laravel/how-to-store-data-in-a-database-using-laravel/
via Lzo Media
No comments:
Post a Comment