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

时间:2019-02-07 13:39:12

标签: php laravel laravel-5 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);
    }
}

我也已经尝试过这两个命令

┌──[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

如果您发现我不应该做的任何事情,请告诉我。

4 个答案:

答案 0 :(得分:1)

您的方法上没有方法= 这就是为什么假设设置了Route :: resource会假定您正在尝试访问show方法的原因。

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

答案 1 :(得分:1)

是的,正如我在最初的评论中所认为的那样,您尚未为表单指定操作-这样可以解决您的问题:

{!! 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');

答案 2 :(得分:1)

这只是路由订购问题。

像这样进行路线排序:

//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');

OR

如果您正在制作CRUD模块,请使用Laravel“资源控制器”路由方法https://laravel.com/docs/5.7/controllers#resource-controllers

首先创建资源控制器:在终端中运行以下命令

php artisan make:controller SkillController --resource

然后将其放在“ routes / web.php”文件中的行下

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

答案 3 :(得分:0)

如果您已经手动编写了这样的路由

//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']]);