我不断收到这个错误,当我尝试在我的项目中创建一个技能
方法应用\ HTTP \控制器\ SkillController ::显示不存在。
我并不需要一个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
请让你发现什么我不应该做的我知道。
它只是路线排序问题。
让路线顺序是这样的:
//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
然后下面放线在“路线/ web.php”文件
Route::resource('skill', 'SkillController');
你没有一个方法=你的。这就是为什么假设路线::资源建立它会假设你正在试图访问演出方法。
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');
要么
你可以删除skillcontroller的整个人工书写路线
它变成这个
Route::resource('skills', 'SkillController', ['only'=> ['index','create','store','delete','edit','update']]);