Lgendary
640
17
Laravel

How to store data in a database using laravel

Posted 1 year ago by Lgendary

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

`<?php

namespace App\Http\Controllers; use Illuminate\Http\Request; use Storage; use App\User;

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/', '[email protected]')->name("user.update"); Route::get('/settings/updateUser/', '[email protected]')->name("user.update");

Please sign in or create an account to participate in this conversation.