Laravel &引用;类别';App\Models\Post';“未找到”;
我试图让我的用户在我的社交媒体网站上发表文章。我已经有了一个“App\Models\Post”。我如何解决它 当我试图提交帖子时,也会出现错误,问题是行中写着:“$post=new post();” 好的,这里说我的帖子看起来大部分都是代码,所以我会写一些没有意义的东西,这样这个小东西就可以运行了。我不是以英语为母语的人,因此如果您发现拼写或语法错误,请纠正我:) 以下是我的控制器的代码:Laravel &引用;类别';App\Models\Post';“未找到”;,laravel,posts,Laravel,Posts,我试图让我的用户在我的社交媒体网站上发表文章。我已经有了一个“App\Models\Post”。我如何解决它 当我试图提交帖子时,也会出现错误,问题是行中写着:“$post=new post();” 好的,这里说我的帖子看起来大部分都是代码,所以我会写一些没有意义的东西,这样这个小东西就可以运行了。我不是以英语为母语的人,因此如果您发现拼写或语法错误,请纠正我:) 以下是我的控制器的代码: <?php namespace App\Http\Controllers; use Illumi
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Post ;
use App\User;
class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('makePost');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function makePost(Request $request)
{
$this->validate($request, array(
'post' => 'required',
'title' => 'nullable|max:50',
'label' => 'nullable|max:25',
));
$post = new Post();
$post->post = $request->post;
$post->title = $request->title;
$post->label = $request->label;
$post->save();
return redirect()->route('index');
}
/**
* 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)
{
//
}
/**
* 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)
{
//
}
尝试使用:
使用App\Post;
而不是使用App\Models\Post 尝试使用:
使用App\Post;
而不是使用App\Models\Post 如果模型目录中的名称空间更改为:
namespace App\Models;
如果没有,则始终可以将控制器更改为:
use App\Post;
如果模型目录中的名称空间更改为:
namespace App\Models;
如果没有,则始终可以将控制器更改为:
use App\Post;
Post模型应该是名称空间App\Models
您可以使用php artisan make:controller PostController--resource--Model=Models\Post
Post Model应该是namespace App\Models,运行一个命令,轻松填充正确的名称空间、模型绑定、控制器名称、模型名称
您可以运行一个命令,通过使用php artisan make:controller PostController--resource--Model=Models\Post
轻松填充正确的名称空间、模型绑定、控制器名称、模型名称,这对我来说似乎是一个完美的解决方案。