Hello all I am a new laravel, I have problem with my project. I have 2 table:
posts: id title category_id
category: id name(PHP, Laravel, Ruby)
Ex: I am insert a post into posts database title=Jonh and chosse two category name(PHP,Laravel), and the result will two column like posts(id=1 title(jonh) category_id(1), id=2 title(jonh) category_id(2)) but it still not work I try to find in google and youtube follow and it not work, and here is my code:
View(create.blade.php)
{!!Form::open(array('route' => 'store', 'method' => 'POST'))!!}
<br>
@foreach($category as $categories)
@endforeach
<br>
{!!Form::close()!!}
Controller(PostsController.php)
public function create()
{
$category = Category::all();
return view('create',compact('category'));
}
public function store(Request $request)
{
$post = new Posts;
$post->title = $request['title'];
$post->category_id = $request['category_id'];
$post->save();
}
Help pls
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire