Я довольно новичок в laravel, и я изо всех сил пытаюсь получить формат моего URL-адреса.Передача переменной через url в laravel
форматирует в
http://mysite/blog?category1 instead of http://mysite/blog/category1
Это файлы, которые я использую, есть способ поместить маршрут в BlogController
Route.php
Route::get('blog/{category}', function($category = null)
{
// get all the blog stuff from database
// if a category was passed, use that
// if no category, get all posts
if ($category)
$posts = Post::where('category', '=', $category)->get();
else
$posts = Post::all();
// show the view with blog posts (app/views/blog.blade.php)
return View::make('blog.index')
->with('posts', $posts);
});
BlogController
class BlogController extends BaseController {
public function index()
{
// get the posts from the database by asking the Active Record for "all"
$posts = Post::all();
// and create a view which we return - note dot syntax to go into folder
return View::make('blog.index', array('posts' => $posts));
}
}
blog.index лезвие
@foreach ($posts as $post)
<h2>{{ $post->id }}</h2>
<p>{{ $post->name }}</p>
<p>{{ $post->category }}</p>
<h2>{{ HTML::link(
action('[email protected]',array($post->category)),
$post->category)}}
@endforeach
вы на апач или Nginx, я думаю, что это проблема переписывания URL. –
Что вы подразумеваете под «It format as»? Когда вы вводите браузер? Или ссылки, созданные Laravel? –
Ссылка, созданная laravel из db. теперь он отображается как http: // localhost/blog? category = category1, и он также не фильтрует результаты db, поэтому что-то не так где-то –