找到NotFoundHttpException错误

时间:2017-06-16 05:50:52

标签: php html css mysqli laravel-5

我想更新个人资料照片,我正在使用Laravel。这样做的时候,我收到了一个错误...对不起英语很差 我包括route,ProfileController,admin.blade.php,profile.blade.php 请帮帮我。

路线是:

Route::get('admin/profile/{username}', 'ProfileController@profile');
Route::post('admin/profile/{username}', 'ProfileController@update_avatar');

profile.blade.php

@extends('layouts.admin')

@section('content')

<style type="text/css">
.profile-img{
    width: 150px;
    height: 150px;
    border: 5px solid white;
}
</style>

<div class="container">
<div class="row">
    <div class="col-md-8 col-md-offset-2">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>{{ $user->username }}'s profile</h4>
            </div>
            <div class="panel-body">
                <div class="col-md-3">
                    <center><img src="{{ asset('/uploads/avatars/'.$user-
>avatar) }}" class="img-responsive img-circle profile-img" alt="" 
style="width: 150px;"></center>
                </div>
                <div class="col-md-4 text-center">
                    <h5>Set Your profile</h5>
                    <form action="{{ url('admin/profile/'.Auth::user()-
>username) }}" method="POST" enctype="multipart/form-data">

                        {{ csrf_field() }}
                        <input type="file" name="file" class="input-sm form-
control" required=""> <br>
                        <button class="btn btn-success btn-sm">Set 
profile</button>
                    </form>
                </div>
                <div class="col-md-5 text-center">
                    {{ Auth::user()->name }} <br>
                    {{ Auth::user()->username }} <br>
                    {{ date('d-m-Y', strtotime(Auth::user()->dob)) }} <br>
                    {{ Auth::user()->email }} <br>
                    <button class="btn btn-warning btn-sm">Follow 
me</button>
                </div>
            </div>
        </div>
    </div>
    </div>
</div>

@endsection

admin.blade.php

<li><a href="{{ url('admin/proflie/'.Auth::user()->username) }}">My Profile</a></li>

ProfileController可

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Admin;
use App\User;
use Auth;
use Image;

class ProfileController extends Controller
{

public function __construct()
{
    $this->middleware('auth:admin');
}

public function profile($username)
{
    $user = Admin::where('username', $username)->first();
    return view('admin.profile')->with('user'->$user);
}

public function update_avatar(Request $request)
{
    if ($request->hasFile('file')) {

        $avatar = $request->file('file');
        $filename = $avatar->getClientOriginalName();

        Image::make($avatar)->resize(300, 300)-
>save(public_path('/uploads/avatars/'. $filename));

        $user = Auth::user();
        $user->avatar = $filename;
        $user->save();
    }
    return view('admin.profile')->with('user'->$user);
  }
  }

请帮助我,谢谢。

2 个答案:

答案 0 :(得分:0)

使用

public function update_avatar(Request $request,$user){

}

你的路线有参数,所以一定要捕捉它。

https://laravel.com/docs/5.4/requests#accessing-the-request

答案 1 :(得分:0)

您在指向路线的链接中输入了一个拼写错误,而不是您提到的个人简介..

<li><a href="{{ url('admin/proflie/'.Auth::user()->username) }}">My Profile</a></li>

这应该有用。

<li><a href="{{ url('admin/profile/'.Auth::user()->username) }}">My Profile</a></li>