vendredi 3 juin 2016

Laravel redirect() in routes.php seem doesn't work.

That is a blog program, you can find it on http://ift.tt/1ReLC24

when I build the grogram and then test it, the website comes a 404 error.

The requested URL /blog was not found on this server.

Could someone tell me where I make the mistake?

the routes.php just like that:

<?php

get('/', function () {
    return redirect('/blog');
});

get('blog', 'BlogController@index');
get('blog/{slug}', 'BlogController@showPost');

the 'BlogController' is like that:

namespace App\Http\Controllers;

use App\Post;
use Carbon\Carbon;

class BlogController extends Controller
{
public function index()
{
    $posts = Post::where('published_at', '<=', Carbon::now())
            ->orderBy('published_at', 'desc')
            ->paginate(config('blog.posts_per_page'));

    return view('blog.index', compact('posts'));
}

public function showPost($slug)
{
    $post = Post::whereSlug($slug)->firstOrFail();
    return view('blog.post')->withPost($post);
}
}

If I don't make the code clear ,you can also find it on http://ift.tt/1U3PkgI thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Y7n2DC
via IFTTT

Aucun commentaire:

Enregistrer un commentaire