簡體   English   中英

方法App \\ Http \\ Controllers \\ SkillController :: show不存在。 -Laravel 5.7

[英]Method App\Http\Controllers\SkillController::show does not exist. - Laravel 5.7

當我嘗試在項目中創建技能時,我一直收到此錯誤

方法App \\ Http \\ Controllers \\ SkillController :: show不存在。

我不需要show()方法,因為我不需要技能對象的show視圖。

這是我的路線塊

//Skill
Route::get('skill','SkillController@index');
Route::get('skill/create','SkillController@create');
Route::post('skill/store','SkillController@store');
Route::get('skill/{id}/edit', 'SkillController@edit');
Route::post('skill/{id}/update','SkillController@update');
Route::delete('skill/{id}/destroy','SkillController@destroy');

這是我的整個SkillController

<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Skill;
use Input, View, File, Image, SSH, Redirect,Response;

class SkillController extends Controller {

    public function index(){

        $skills = Skill::orderBy('updated_at', 'desc')->orderBy('created_at', 'asc')->where('img_path','==',NULL)->get();

        $first_color  = $skills[0]->color_code;
        $second_color = $skills[1]->color_code;
        $third_color  = $skills[2]->color_code;
        $fourth_color = $skills[3]->color_code;
        $fift_color   = $skills[4]->color_code;

        return View::make('layouts.be.skills.index', get_defined_vars());
    }

    public function all(){
        return Skill::all()->pluck('name');
    }

    public function create(){

        $skillTypes = ['Build System','Development Environment','Server Management','Operating System','IDE','Creative Suite','Video Editing','Package Management','Git Repository','Web Scaffolding','CSS Precompiler','Scripting','Framework','DBMS','Unit Test','Automation Testing','Cloud Platform','Hosting Provider','Content Management', 'API', 'Authentication' , 'Integration','Language','Web Server','Project Managment','Documentation','Utility','Network Analyzer' ];

        sort($skillTypes);

        return View::make('layouts.be.skills.create', get_defined_vars());
    }

    public function edit($id){

        $skillTypes = ['Build System','Development Environment','Server Management','Operating System','IDE','Creative Suite','Video Editing','Package Management','Git Repository','Web Scaffolding','CSS Precompiler','Scripting','Framework','DBMS','Unit Test','Automation Testing','Cloud Platform','Hosting Provider','Content Management', 'API', 'Authentication' , 'Integration','Language','Web Server','Project Managment','Documentation','Utility','Network Analyzer' ];

        sort($skillTypes);

        $skill = Skill::findOrFail($id);
        return View::make('layouts.be.skills.edit', get_defined_vars());
    }

    public function store(){

        $skill             = new Skill;
        $skill->type       = Input::get('type');
        $skill->name       = Input::get('name');
        $skill->value      = Input::get('value');
        $skill->color_code = Input::get('color_code');
        $skill->save();

        if (Input::hasFile('logo_path')) {
            $image_path      = '/assets/img/skill/';
            $path            = public_path() . $image_path;
            $file            = Input::file('logo_path');
            $img_name        = $skill->id.'.png';
            $uploadSuccess   = $file->move($path, $img_name);
            $file_path       = $path . $img_name;
            $skill->img_path = $image_path . $img_name;
            $crop_file       = Image::make($file_path)->fit(20,20);
            $crop_file->save($path . 'crop-'.$img_name, 65);
        }else {
            $skill->img_path = Input::get('logo_path');
        }

        $skill->save();

        return Redirect::to('/skill') ->with('success','The skill was created succesfully!');

    }

    public function update($id){

        $inputs            = Input::all();
        $skill             = Skill::find($id);
        $skill->name       = Input::get('name');
        $skill->type       = Input::get('type');
        $skill->value      = Input::get('value');
        $skill->color_code = Input::get('color_code');

        $skill->save();

        if (Input::hasFile('logo_path')) {

            $image_path      = '/assets/img/skill/';
            $path            = public_path() . $image_path;
            $file            = Input::file('logo_path');
            $img_name        = $skill->id.'.png';
            $uploadSuccess   = $file->move($path, $img_name);
            $file_path       = $path . $img_name;
            $skill->img_path = $image_path . $img_name;
            $crop_file       = Image::make($file_path)->fit(20,20);
            $crop_file->save($path . 'crop-'.$img_name, 65);
        } else {
            $skill->img_path = Input::get('logo_path');
        }

        $skill->save();

        return Redirect::to('/skill') ->with('success','The skill was updated succesfully!');

    }

    public function destroy($id){

        $skill = Skill::find($id);
        $skill->delete();

        $image_path      = '/assets/img/skill/';
        $path            = public_path() . $image_path;
        File::deleteDirectory($path);

        return Redirect::to('/skill') ->with('success','The skill was deleted succesfully!');

    }

    public function skilldata(Request $request){
        $skill = str_replace("-"," ",$request->skill);
        $data = Skill::where(DB::raw('LOWER(type)'),'=',$skill)->get();
        return response()->json($data, 200);
    }
}

我也已經嘗試過這2個命令

┌──[root@bheng]──[/home/forge/bheng]                                                                         
└── php artisan cache:clear                                                                                  
Application cache cleared!                                                                                   

┌──[root@bheng]──[/home/forge/bheng]                                                                         
└── composer dumpauto                                                                                        
Do not run Composer as root/super user! See https://getcomposer.org/root for details                         
Generating autoload files                                                                                    
> Illuminate\Foundation\ComposerScripts::postAutoloadDump                                                    
> @php artisan package:discover                                                                              
Discovered Package: nesbot/carbon                                                                            
Discovered Package: laravel/slack-notification-channel                                                       
Discovered Package: laravel/nexmo-notification-channel
Discovered Package: laravelcollective/remote
Discovered Package: htmlmin/htmlmin
Discovered Package: intervention/image
Discovered Package: laravelcollective/html
Package manifest generated successfully.
You have new mail in /var/mail/root
┌──[root@bheng]──[/home/forge/bheng] 
└── 

skill.create.blade.php

@extends('layouts.be.master')
@section('content')


<div class="card-body card-padding">
    <div class="row">

        {!! Form::open(array('class' => 'form-horizontal', 'role' =>'form', 'url'=>'skill/store','files' => true)) !!}


        <div class="col-sm-4">




            {{-- Name --}}
            <div class="form-group">
                <label for="email" class="col-sm-2 control-label">Name</label>
                <div class="col-sm-10">
                    <input type="text" value="{{Request::old('name')}}"  value="" name="name" class="form-control" id="name" placeholder="Name">
                </div>
            </div>

            {{-- Type --}}
            <div class="form-group">
                <label for="email" class="col-sm-2 control-label">Type</label>
                <div class="col-sm-10">
                    <select name="type" class="form-control">
                      @foreach($skillTypes as $item)
                        <option value="{{ $item }}">{{ $item }}</option>
                      @endforeach
                    </select>
                </div>
            </div>

            {{-- Value --}}
            <div class="form-group">
                <label class="col-sm-2 control-label">Value</label>
                <div class="col-sm-8">
                    <br>
                    <input type="range" id="range-value" value="93" name="value">
                </div>
                <div class="col-sm-2">
                    <h3 id="text-value"></h3>
                </div>
            </div>


            {{-- Color --}}
            <div class="form-group">
                <label for="email" class="col-sm-2 control-label">Color</label>
                <div class="col-sm-2">
                    <input type="color" name="color_code" class="form-control" placeholder="Color" id="example-color-input">

                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-4 col-sm-8">
                    <a class="btn btn-default" href="/skill"> Cancel </a>
                    <button type="submit" class="btn btn-info">Create</button>
                </div>
            </div>



        </div>
        <div class="col-sm-8">



            {{-- Icon --}}
            <div class="form-group">
                <label class="col-sm-2 control-label" >Icon</label>
                <div class="col-sm-10">

                    <img name="logo_path" id="skill-icon" width="300px"><br><br>

                    <input type="file" class="form-control" name="logo_path" aria-describedby="fileHelp">
                </div>


                <label class="col-sm-2 control-label" >Icon URL </label>
                <div class="col-sm-10">

                    <input id="url-logo" name="logo_path" type="text" class="form-control">

                </div>



            </div>

        </div>

        {!!Form::close()!!}


    </div>
</div>

@stop

@section('custom-scripts')

    <script type="text/javascript" src="/js/Vibrant.js"></script>

    <script type="text/javascript">

        function readLogo(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.onload = function (e) {
                    $('#skill-icon').attr('src', e.target.result);
                }
                reader.readAsDataURL(input.files[0]);
            }
        }

        // Update media preview with base64 image
        $( "input[name*='logo_path']" ).change(function(){
            readLogo(this);
        });

        $( "#url-logo" ).on('keyup',function(){
            $('#skill-icon').attr('src', $( "#url-logo" ).val());
        });

        $('#text-value').text($('#range-value').val());
        $('#range-value').change(function(){
            $('#text-value').text($('#range-value').val());
        });

        // Icon
        var icon = $('#skill-icon');
        icon.attr('src', $( "#url-logo" ).val());

        $( "#url-logo" ).on('keyup',function(){

            var vibrant = new Vibrant(icon[0]);
            var swatches = vibrant.swatches()
            for (var swatch in swatches)
                if (swatches.hasOwnProperty(swatch) && swatches[swatch])
                    // console.log(swatches[swatch].getHex());
                    var color = swatches[swatch].getHex();
                    $( "input[name*='color_code']" ).val(color)
                    console.log('%c >>>>>>>>>>>>>>', "color:" + String(color) + ";");
                    console.log('color',color);

                    // Vibrant #3c62ac
                    // Muted #7484ab
                    // DarkVibrant #345cab
                    // DarkMuted #101010
                    // LightVibrant #849ccc

        });


    </script>
@stop

如果您發現我不應該做的任何事情,請告訴我。

它只是路由訂購問題。

像這樣制作路線順序:

//Skill
Route::post('skill/store','SkillController@store');
Route::get('skill','SkillController@index');
Route::get('skill/create','SkillController@create');
Route::post('skill/{id}/update','SkillController@update');
Route::delete('skill/{id}/destroy','SkillController@destroy');
Route::get('skill/{id}/edit', 'SkillController@edit');

要么

如果您正在制作CRUD模塊,請使用Laravel``資源控制器''路由方法https://laravel.com/docs/5.7/controllers#resource-controllers

首先創建資源控制器:在終端中運行以下命令

php artisan make:controller SkillController --resource

然后放在“ routes / web.php”文件下面

Route::resource('skill', 'SkillController');

您的上沒有method =,這就是為什么假設設置了Route :: resource會假定您正在嘗試訪問show方法。

Form::open(array('url' => 'foo/bar', 'method' => 'POST'))

是的,正如我在最初的評論中所認為的那樣,您尚未為表單指定操作-這樣可以解決您的問題:

{!! Form::open(array('class' => 'form-horizontal', 'role' =>'form', 'url'=>'skill/store', 'action' => 'SkillController@store' ,'files' => true)) !!}

另外,您的路線不正確-您的路線應為:

Route::get('skill','SkillController@index');
Route::get('skill/create','SkillController@create');
Route::post('skill/store','SkillController@store');
Route::get('skill/{id}/edit', 'SkillController@edit');
Route::patch('skill/{id}/update','SkillController@update'); //this should be put or patch not post
Route::delete('skill/{id}/destroy','SkillController@destroy');

如果您已經手動編寫了這樣的路線

//Skill
Route::get('skill','SkillController@index');
Route::get('skill/create','SkillController@create');
Route::post('skill/store','SkillController@store');
Route::get('skill/{id}/edit', 'SkillController@edit');
Route::post('skill/{id}/update','SkillController@update');
Route::delete('skill/{id}/destroy','SkillController@destroy');

那么您就不需要這個了,這段代碼應該在您的路線上

Route::resource('skills','SkillController');

要么

您可以刪除技能控制器的整個手動書面路線

換成這個

Route::resource('skills', 'SkillController', ['only'=> ['index','create','store','delete','edit','update']]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM