2016-10-18 2 views
1

이 오류를 해결하는 방법을 묻고 싶습니다. 나는 내가 userprofile\edit.blade.php경로에 대한 필수 매개 변수가 누락되었습니다.

에 페이지를 재배치 할 내가보기 userprofile\create.blade.php에서 사용자 정보를 가지고 [Route: userprofile.edit] [URI: userprofile/{userprofile}/edit]. (View: C:\xampp\htdocs\code\task1\resources\views\userprofile\create.blade.php)

과 버튼을 제출 한 후 필요한 매개 변수를 누락이 오류가이 또한 내 userProfileController

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 
use App\User; 

class userProfileController extends Controller 
{ 
    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     // 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function create() 
    { 
     return view("userprofile.create"); 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function store(Request $request) 
    { 
     // 
    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function show($id) 
    { 
     // 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function edit($id) 
    { 
     $user = User::find($id); 
     return view('userprofile.edit')->withUser($user); 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function update(Request $request, $id) 
    { 
     // 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function destroy($id) 
    { 
     // 
    } 
} 

입니다 이보기의 경로

Route::group(['namespace' => 'User'], function(){ 
Route::get('/userprofile/{id}/edit', ['as' => 'userprofile.edit', 'uses' => '[email protected]']); 
}); 


Route::resource('userprofile','userProfileController'); 

create.blade.php

<input type="submit" class="btn btn-primary" action="{{ route('userprofile.edit') }}" value="Edit profile"> 

에서 버튼의 경로 액션이 오류가 왜 어떤 생각이 있다면, 저를 보내주십시오! 감사합니다.

답변

-1

대신

<input type="submit" class="btn btn-primary" action="{{ route('userprofile.edit') }}" value="Edit profile"> 

사용의

<a href="{{url('/userprofile/'.PROFILE ID.'/edit')" class="btn btn-primary" >Edit profile</a> 

프로필 ID는 사용자가 입력 필드에 조치를 추가 할 수 없습니다 ID

+0

경로 대신 URL을 사용하는 이유는 무엇입니까? – Devmasta

+0

버튼을 전송하고 단추를 제출하면 같은보기가 있고이 http : // localhost : 8080/code/task1/public/userprofile/create? user_name = admin % 40example.com에 경로가 변경됩니다. – Devmasta

0

해야합니다. form 태그에 작업을 추가하십시오. 양식 동작에 id을 전달하지 않았습니다. 내가 ID를 통과 한처럼 행동에 ID를 추가 = 1

<form method="post" action="{{ route('userprofile.edit', ['id' => 1]) }}"> 

업데이트

당신은 주어진 데이터와 사용자를 생성해야 우선 그 후에 당신은 생성과 편집 페이지로 리디렉션 신분증.

+0

버튼을 제출 한 후 localhost : 8080/code/task1/public/userprofile/created? user_name = admin % 40example.com – Devmasta

0

당신은 지금처럼 edit과 다른 방법으로 전달 된 ID에 대한 기본 값을 설정해야합니다

public function edit($id = null) 
{ 
    $user = User::find($id); 
    return view('userprofile.edit')->withUser($user); 
} 

을 여기, 우리가 nullid의 기본 값을 설정합니다. 다음은 null의 경우, 귀하의 방법으로 확인하고 만약 그렇다면, 당신은 그 상황에서 할 싶어 어떤 오류나로 반환 :

public function edit($id = null) 
{ 
    if(!$id) 
     return back()->with(['error'=>'No document selected for editing.']); 

    $user = User::find($id); 
    return view('userprofile.edit')->withUser($user); 
} 

if(!$id) return back()->with(['error'=>'No document selected for editing.']);

이 수표하고 ID가있는 경우 null이면 사용자에게 돌아가서 알립니다 (블레이드보기에서 오류를 확인하고 오류가 있는지 확인해야합니다).

+0

id 값을 설정하는 데 문제가 없으므로 올바른 방법으로 ID를 제공합니다. ,하지만 나는 edit.blade.php에 페이지를 재배치하는데 문제가있다. – Devmasta

관련 문제