I'm new to laravel, right now I'm stuck on getting video_id on my posts table where I should make it equal to id on my videos table. posts table = http://ift.tt/2am42fD videos table = http://ift.tt/2ayoUUr Route: displaying video ID when i post it:
Route::get('/test/{videoID}', function($videoID) {
$video = Video::where('id', $videoID)->firstOrFail();
$posts = Post::all();
return View::make('layouts.viewvideo')->with(['video' => $video, 'posts' => $posts]);});
PostController:
public function postCreatePost(Request $request) {
$post = new Post();
$post->body = $request['body'];
$request->user()->posts()->save($post);
return redirect()->back();
Post view:
@foreach($video->posts as $post)
<article class="post" data-postid="">
<div class="postbody">
<p></p>
</div>
<?php
$test = preg_replace('/([^\s]{20})(?=[^\s])/', '$1'.'<wbr>', $post->body);
?>
<div class="info">
Posted by on
</div>
</article>
@endforeach
I tried to edit video_id column on my posts table and change it equal to id of my video and it worked, but how can I automatically assign it once I create post on a specific video? Thank you.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire