mercredi 17 juillet 2019

Route issue:Class Controller does not exist in Laravel 5.8

I am creating a profile section. And show.blade.php is the profile edit part.

But I cannot see show.blade.php.

I got a following error.

error image

Here is my code.

web.php

Route::resource('channels', 'ChannelController');

php artisan route:list in terminal. And this is the result. php artisan route:list

app.blade.php once I click here I can jump to show.blade.php

<a class="dropdown-item" href=""> My Channel</a>

controller.php

<?php

namespace Laratube\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

ChannelController.php

    <?php

namespace Laratube\Http\Controllers;

use Illuminate\Http\Request;

class ChannelController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * 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(Channel $channel)
    {
        return view('channels.show', compact('channel'));
    }

    /**
     * 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)
    {
        //
    }
}

show.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    
                </div>

                <div class="card-body">
                    <form id="update-channel-form" action="" method="POST" enctype="multipart/form-data">
                        @csrf

                        @method('PATCh')
                        <div class="form-group">   
                            <label for="name" class="form-control-label">
                                Name
                            </label>
                            <input id="name" name="name" value="" type="text" class="form-control">
                        </div>
                        <div class="form-group">
                            <label for="description" class="form-control-label">
                                Description
                            </label>
                            <textarea name="description" id="description" cols="3" rows="3" class="form-control">
                                
                            </textarea>
                        </div>

                        <button class="btn btn-info" type="submit">Update</button>

                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
@endsection

I tried following things.

    php artisan cache:clear

    composer update

    composer dump-autoload

    php artisan db:seed

But still it doesn't work.

I am glad if someone helps me out.

I guess, I have something wrong with my route. This route also did not work.

Route::resource('channels', 'ChannelController')->name('channels.show');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire