mailman

188 经验值

Route::get('/', 'sitesController@index');
Route::get('/about','sitesController@about');
Route::get('/wenzhang','sitesController@wenzhang');
Route::get('/jiaocheng','sitesController@jiaocheng');
Route::get('/liuyan','sitesController@liuyan');

Route::get('/articles','articleController@index');
Route::get('/articles/{id}','articleController@show');
Route::get('/articles/{id}','ArticleController@show');   
routes.php 

用{{ url('ArticleController',$value->id) }}没有问题。

index.blade.php

@extends('layout')
@section('content')
    <h1>文章列表</h1>
    @foreach($articles as $value)
        <h2><a href=" {{ action('ArticleController@show',[$value->id]) }} "> {{ $value->title }} </a></h2>
        <h3> {{ $value->intro }} </h3>
    @endforeach
@stop

ArticleController.php


<?php
namespace App\Http\Controllers;
use App\Article;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class ArticleController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $articles = Article::all();
        return view('article.index',compact('articles'));
    }

    /**
     * Show the form for creating a new resource.
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
   public function show($id)
    {
        $articles = Article::findOrfail($id);
        return $articles;
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
ErrorException in UrlGenerator.php line 558:
Action App\Http\Controllers\ArticleController@show not defined. (View: F:\www\stlv\resources\views\article\index.blade.php)

那里错了。

为啥不要把导航条写在layout文件中呢?

控制器怎么用if判断
为啥不能写在layout里面。这个是公用的文件??