Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CommentController.php第43行中的Laravel 5.1 ErrorException:未定义索引:正文_Php_Mysql_Laravel_Laravel 5.1 - Fatal编程技术网

CommentController.php第43行中的Laravel 5.1 ErrorException:未定义索引:正文

CommentController.php第43行中的Laravel 5.1 ErrorException:未定义索引:正文,php,mysql,laravel,laravel-5.1,Php,Mysql,Laravel,Laravel 5.1,我正在建立一个项目,用户可以上传项目,其他用户可以评论彼此的项目 现在我可以上传项目并构建评论系统,但现在我不能再上传项目了,我只能对已经存储在数据库中的项目进行评论 有人知道我为什么不再能够存储项目了 我的路线: // add comment Route::post('projects/{id}','CommentController@store'); //Project routes REST methode Route::post('projects/store', 'ProjectsCo

我正在建立一个项目,用户可以上传项目,其他用户可以评论彼此的项目

现在我可以上传项目并构建评论系统,但现在我不能再上传项目了,我只能对已经存储在数据库中的项目进行评论

有人知道我为什么不再能够存储项目了

我的路线:

// add comment
Route::post('projects/{id}','CommentController@store');
//Project routes REST methode
Route::post('projects/store', 'ProjectsController@store');
Route::resource('projects', 'ProjectsController');
我的项目控制器:

public function index()
{
    $projects = Project::all();
    //return $projects;
    return view('projects.index', compact('projects'));
}

public function create()
{
    return view('projects.create');
}

public function store(Request $request)
{

  // getting all of the post data
      $file = array('image' => Input::file('image'));
      // setting up rules
      $rules = array('image' => 'required',); //mimes:jpeg,bmp,png and for max size max:10000
      // doing the validation, passing post data, rules and the messages
      $validator = Validator::make($file, $rules);
      if ($validator->fails())
      {
        // send back to the page with the input data and errors
        return Redirect::to('projects/create')->withInput()->withErrors($validator);
      }
      else
      {
        // checking file is valid.
        if (Input::file('image')->isValid())
        {
          $destinationPath = 'uploads/projects'; // upload path
          $extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
          $fileName = rand(11111,99999).'.'.$extension; // renameing image
          Input::file('image')->move($destinationPath, $fileName); // uploading file to given path
          // sending back with message
          Session::flash('success', 'Upload successfully'); 
        }
        else
        {
          // sending back with error message.
          Session::flash('error', 'uploaded file is not valid');
          return Redirect::to('projects/create');
        }
      }

      $input = Request::all();
      $project = new Project;
      $project->user_id = Auth::id();
      $project->title = $input['title'];
      //$project->tags = $input['tags'];
      $project->summary = $input['summary'];
      $project->file_name = $fileName;
      $project->published_at = Carbon::now();
      $project->save();
      return Redirect::to('projects');

}

public function show($id)
{
    $input = Request::all();
    $project = Project::all()->load("User");
    //$project_comments = Comment::where('on_projects', '=', $id)->join('users', 'users.id', '=', 'comments.from_user')->get();

    $project_comments = DB::table('comments')
        ->select('body', 'name')
        ->where('on_projects', '=', $id)
        ->join('users', 'users.id', '=', 'comments.from_user')
        ->get();

    return view('projects.show', ['project' => Project::findOrFail($id), 'comments' => $project_comments]);

}
我的控制器

public function store()
{
    $input = Request::all();
    $comment = new Comment;
    $comment->body = $input['body'];
    $comment->on_projects = $input['project_id'];
    $comment->from_user = Auth::user()->id;
    $comment->save();
    return redirect('projects/'.$input['project_id']);

}
我的项目模型

class Project extends Model
{
protected $fillable = [
'user_id',
'title',
//'tags',
'summary',
'file_name',
'published_at'
];
public function User()
{
    return $this->belongsTo('App\User');
}

/**
 * Haal de tags op die gerelateerd zijn aan desbetreffende project
 */

public function tags()
{
    return $this->belongsToMany('App\Tag')->withTimestamps();
}
}
我的评论模式:

class Comment extends Model
{
//comments table in database
protected $guarded = [];

protected $table = 'comments';

public function user()
{
    return $this->belongsTo('App\User');
}

// returns post of any comment
public function post()
{
    return $this->belongsTo('App\Project','project_id');
}


public $timestamps = false;
}

我通过像这样重新安排路线来解决这个问题

//Project routes REST methode
Route::post('projects/store', 'ProjectsController@store');
Route::resource('projects', 'ProjectsController');
// add comment
Route::post('projects/{id}','CommentController@store');

我通过像这样重新安排路线来解决这个问题

//Project routes REST methode
Route::post('projects/store', 'ProjectsController@store');
Route::resource('projects', 'ProjectsController');
// add comment
Route::post('projects/{id}','CommentController@store');

我通过像这样重新安排路线来解决这个问题

//Project routes REST methode
Route::post('projects/store', 'ProjectsController@store');
Route::resource('projects', 'ProjectsController');
// add comment
Route::post('projects/{id}','CommentController@store');

我通过像这样重新安排路线来解决这个问题

//Project routes REST methode
Route::post('projects/store', 'ProjectsController@store');
Route::resource('projects', 'ProjectsController');
// add comment
Route::post('projects/{id}','CommentController@store');

问题是$input['body']不存在。。检查您的视图输入是否有此名称正文或其他..感谢您的评论,但此问题已解决!问题是$input['body']不存在。。检查您的视图输入是否有此名称正文或其他..感谢您的评论,但此问题已解决!问题是$input['body']不存在。。检查您的视图输入是否有此名称正文或其他..感谢您的评论,但此问题已解决!问题是$input['body']不存在。。检查您的视图输入是否有此名称正文或其他..感谢您的评论,但此问题已解决!