如何使用laravel在数据库中存储数据

时间:2018-05-06 08:03:30

标签: laravel

请问这个代码有什么问题...我是新手,这个任务是完成的,我看YouTube并在线阅读,但我似乎可以弄清楚如何在数据库中存储记录......

这是UserController

  

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

} }

这是我的路线

  

路线::交( '/设置/ UpdateUser两个/',   'UserController的@ UpdateUser两个') - >名称( “user.update”);   路线::得到( '/设置/ UpdateUser两个/',   'UserController的@ UpdateUser两个') - >名称( “user.update”);

0 个答案:

没有答案