我在幼虫上使用了模型关系。
当我访问viewpage但显示错误类'App/Board‘not found时。
我在应用程序文件夹里有Board.php。
我不知道出了什么问题。
我花了12个小时。请给我一些建议。
控制器
namespace App\Http\Controllers;
use App\Board;
use App\Person;
use App\Http\Requests\PostRequest;
use Illuminate\Http\Request;
class ReviewController extends Controller
{
.
.
.
public function show()
{
$items_p = Person::all();
$data = [
'items_p' => $items_p
];
return view('Review.show', $data);
}
}Board.php(在应用程序文件夹中)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Board extends Model
{
protected $fillable = [
'person_id',
'message'
];
public function getData()
{
return $this->message;
}
}Person.php(在应用程序文件夹中)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
protected $fillable = [
'name'
];
public function board()
{
return $this->hasOne('App/Board');
}
}视图(Review.show)
.
.
.
<ul>
<li>
@foreach ($items_p as $item)
{{$item->name}}
{{$item->board->getData()}}
@endforeach
</li>
</ul>
・
・
・发布于 2020-06-12 18:29:06
斜杠中有一个错误。您已通过/。应该是\。
class Person extends Model
{
protected $fillable = [
'name'
];
public function board()
{
return $this->hasOne('App\Board');
}
}https://stackoverflow.com/questions/62342057
复制相似问题