Laravel
1
Вклад в тег
Post::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('title');
$table->text('content');
});
protected $fillable = ['id', 'title', 'content',];
public function store()
{
Post::create([
'title'=>request('title'),
'content'=> request('content'),
]);
return back();
}
<form action = "/poststore" enctype="multipart/form-data" method = "POST">
{{csrf_field()}}
<label for="">Title</label><br />
<input type='text' class="form-control" size="30%" placeholder="" name='title' /><br />
<label for="">content</label><br />
<textarea name='content' class="form-control" rows="5" cols="80"></textarea>
<input class=""type = 'submit' value = "Добавить запись"/>
</form>
Route::post('/postsotore', 'PostController@store');
public function index()
{
$posts = App\Post::all();(мы получаем все записи из таблици)
return view('welcome', compact('posts');
}
@foreach($posts as $post)
{{ $post->title(столбец который необходимо вывести)}}
{{$post->content}}
@endforeach