это мои комментарии таблицакак я показать так много комментариев в одном сообщении на форуме
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('post_id')->unsigned();
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
$table->string('comments');
$table->timestamps();
});
}
это мой пост стол
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->index();
$table->timestamps();
});
на мой пост модели я дать hasMany
public function comments()
{
return $this->hasMany('App\Comment');
}
на мой комментарий модель i give принадлежитToo
public function post()
{
return $this->belongsTo('App\Post');
}
это мой контроллер
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Http\Requests;
use App\comment;
use App\post;
use Crypt;
class PostController extends Controller
{
public function index() {
$posts = post::orderBy('created_at', 'desc')->paginate(9);
return view('post.index', compact('posts'));
}
public function create(){
return view('post.create');
}
public function store(Request $request){
$post = new post;
$post->title = $request->title;
$post->save();
return redirect()->route('rules');
}
public function show($title){
$post = post::where('title', $title)->first();
$comments = post::orderBy('created_at', 'desc')->paginate(10);
return view('post.show', compact('post', 'comments'));
}
public function storecomment(request $request){
$comment = new comment;
$comment->post_id = Crypt::decrypt(Input::get('post_id'));
$comment->comments = $request->comments;
$comment->save();
return redirect()->route('rules');
}
}
я есть вид Еогеасп, но я вижу все комментарии в каждом посте , что я печатаю на мой взгляд, чтобы показать комментарии с POST_ID
некоторые вещи до сих пор я не хватает я получаю эту ошибку Метод orderBy не существует. (Вид: E: \ xampp \ htdocs \ new \ resources \ views \ post \ show.blade.php) –