Laravel 5路线错误,错误显示,解决方案?扩展的route.php无法正常工作 [英] Laravel 5 error in routes, error showing, solution? Extended route.php not working properly

查看:54
本文介绍了Laravel 5路线错误,错误显示,解决方案?扩展的route.php无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

laravel 5库发布并且在尝试所有这些时路由异常错误。



我尝试了什么:



路线:



使用Illuminate\Support\Facades\Input;

使用Illuminate \Http\Request;

使用App\Providers \ RouteServiceProvider;

使用Cartalyst \ Alerts \ Laravel \ AlertsServiceProvider;

使用App\student;

使用App \faculty;



/ *

| ------------------------------------------- -------------------------------

|申请路线

| --------------------------------------- -----------------------------------

|

|您可以在这里注册申请的所有路线。

|这是一件轻而易举的事。只需告诉Laravel它应该响应的URI

|当请求URI时,给控制器调用。

|

* /







Route :: get('std',function(){

返回视图('student');

});

Route :: get('fac',function(){

返回视图('faculty');

} );

Route :: get('del',function(){

返回视图('stddelete');

});

Route :: get('upd',function(){

返回视图('stdupdate');

});

Route :: get('sh',function(){

$ show = DB :: table('student')

- > select('student.name','student.address')

- > get();

返回视图('show',compact('show', $ show));

});



Route :: get('addstudent',function()

{

$ student1 =新生;

$ student =输入:: all();

$ student1- > name = $ student ['name'];

$ student1-> address = $ student ['address'];

$ student1-> save( );

返回视图('学生');





});

Route :: get('student','std @ addstudent');

Route :: get('faculty','std @addfaculty');

Route :: get('delete','std @ delete');

Route :: get('update','std @ update');

< br $>
型号:





命名空间App;



使用Illuminate \Database \ Eloquent \ Model;



班级学生扩展模型

{



public $ timestamps = false;





protected $ table ='student';

/ **

*可分配的属性。

*



* /

protected $ fillable = [

'名字','地址',

];





}

< br $>




控制器:



命名空间App\Http\Controllers;

使用Illuminate \Http\Request;

使用App\Http\Requests;

使用Illuminate\Support\Facades \输入;

使用App\student;

使用App \faculty;

使用Illuminate\Routing \Controller; < br $>


class std extends Controller

{

public function addstudent()

{

$ student =新学生;

$ student-> name = input :: get('name');

$ student- > address = input :: get('address');

$ student-> save();

返回视图('student');

}

公共功能addfaculty()

{

$ fac =新教员;

$ fac-> name = input :: get('name');

$ fac-> addr ess = input :: get('address');

$ fac-> save();

返回视图('faculty');

}

公共功能删除()

{

$ id = input :: get('id');

$ data = student :: where('id','=',$ id) - > delete();



返回视图( 'stddelete');





}

公共功能更新()

{

$ id = input :: get('id');

$ name = input :: get('name');

$ address = input :: get('address');

$ data = student :: where('id','=',$ id) - > update(['name'=> $ name,'address'=> $ address]);

}

}





views:



studentblade.php(ajax已实施):::



< meta name =_ tokencontent ={{csrf_token()}} />

< form role =form>





< input type = textname =nameclass =form-controlid ='name'>



< input type =textname =address class =form-controlid ='address'>



< input type =buttonvalue =添加学生class =form-控制class =btn btn-primary>



< / form>

< script src ='http:/ /cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

< script src =js / index.js &G t;< / script>



< script type =text / javascript>



// $ .ajaxSetup({

// headers:{'X-CSRF-Token':$('meta [name = _token]')。attr('content')}

//});

函数add()

{



var name = $('#name')。val();

var address = $('#address')。val();



提醒(姓名);

提醒(地址);

$ .ajax({



类型:'get',

url:http:// localhost / newschool / addstudent,

数据:{

'name':姓名,

'地址':地址

},

成功:功能(回复)

{

$('#name')。val();

$('#phone')。val();

警告(学生添加);



// $ .get(http:// localhost:84 / Np / addstudent,功能(数据)

// {



//提醒(数据);

//});

}

});

}

< / script>







stddelete.blade.php :::



< form action =deleterole =formmethod = get>





< input type =textname =idclass =form-control> ;



< input type =submitvalue =deleteclass =form-controlclass =btn btn-primary>



< / form>





stdupdate.blade.php


< form action =updaterole =formmethod =get>







< input type =textname =idclass =form-control>

< input type = textname =nameclass =form-control>



< input type =textname =addressclass =form -control>



< input type =submitvalue =updateclass =form-c ontrolclass =btn btn-primary>



< / form>





show.blade.php ::::



< form action =showrole =formmethod =get >



@foreach($ show as $ shows)

@endforeach

< td> {{$ shows-> address}}
name address
{{$ shows-> name}}


< / form>

< br $> b $ b

faculty.blade.php :::





<表格action =facultyrole =formmethod =get>





< input type =textname =nameclass =form-control>



< input type =textname =addressclass =form-control> ;



< input type =submitvalue =添加教员class =form-controlclass =btn btn-primary>



< / form>

laravel 5 library issued and route exception error when i m trying all this.

What I have tried:

routes:

use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use App\Providers\RouteServiceProvider;
use Cartalyst\Alerts\Laravel\AlertsServiceProvider;
use App\student;
use App\faculty;

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/



Route::get('std', function () {
return view('student');
});
Route::get('fac', function () {
return view('faculty');
});
Route::get('del', function () {
return view('stddelete');
});
Route::get('upd', function () {
return view('stdupdate');
});
Route::get('sh',function(){
$show=DB::table('student')
->select('student.name','student.address')
->get();
return view('show',compact('show',$show));
});

Route::get('addstudent',function()
{
$student1=new student;
$student=Input::all();
$student1->name=$student['name'];
$student1->address=$student['address'];
$student1->save();
return view('student');


});
Route::get('student','std@addstudent');
Route::get('faculty','std@addfaculty');
Route::get('delete','std@delete');
Route::get('update','std@update');

model:


namespace App;

use Illuminate\Database\Eloquent\Model;

class student extends Model
{

public $timestamps = false;


protected $table = 'student';
/**
* The attributes that are mass assignable.
*

*/
protected $fillable = [
'name','address',
];


}



controller:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Input;
use App\student;
use App\faculty;
use Illuminate\Routing\Controller;

class std extends Controller
{
public function addstudent()
{
$student=new student;
$student->name=input::get('name');
$student->address=input::get('address');
$student->save();
return view('student');
}
public function addfaculty()
{
$fac=new faculty;
$fac->name=input::get('name');
$fac->address=input::get('address');
$fac->save();
return view('faculty');
}
public function delete()
{
$id=input::get('id');
$data = student::where('id', '=',$id )->delete();

return view('stddelete');


}
public function update()
{
$id=input::get('id');
$name=input::get('name');
$address=input::get('address');
$data= student::where('id','=',$id)->update(['name'=>$name,'address'=>$address]);
}
}


views:

studentblade.php(ajax implemented):::

<meta name="_token" content="{{ csrf_token() }}"/>
<form role="form">


<input type="text" name="name" class="form-control" id='name'>

<input type="text" name="address" class="form-control" id='address'>

<input type="button" value="Add student" class="form-control" class="btn btn-primary" >

</form>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>

<script type="text/javascript">

//$.ajaxSetup({
// headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
//});
function add()
{

var name=$('#name').val();
var address=$('#address').val();

alert(name);
alert(address);
$.ajax({

type:'get',
url:"http://localhost/newschool/addstudent",
data:{
'name':name,
'address':address
},
success:function(response)
{
$('#name').val("");
$('#phone').val("");
alert("student added");

// $.get("http://localhost:84/Np/addstudent", function( data )
// {

// alert(data);
// });
}
});
}
</script>



stddelete.blade.php:::

<form action="delete" role="form" method="get">


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

<input type="submit" value="delete" class="form-control" class="btn btn-primary">

</form>


stdupdate.blade.php

<form action="update" role="form" method="get">



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

<input type="text" name="address" class="form-control">

<input type="submit" value="update" class="form-control" class="btn btn-primary">

</form>


show.blade.php::::

<form action="show" role="form" method="get">

@foreach($show as $shows)
@endforeach

nameaddress
{{$shows->name}} {{$shows->address}}

</form>


faculty.blade.php:::


<form action="faculty" role="form" method="get">


<input type="text" name="name" class="form-control">

<input type="text" name="address" class="form-control">

<input type="submit" value="Add faculty" class="form-control" class="btn btn-primary">

</form>

推荐答案

show = DB :: table('student')

- > select('student.name','student.address')

- > get();

返回视图('show',compact('show',
show=DB::table('student')
->select('student.name','student.address')
->get();
return view('show',compact('show',


show));

});



Route :: get('addstudent',function()

{
show));
});

Route::get('addstudent',function()
{

< br>

student1 =新生;
student1=new student;


这篇关于Laravel 5路线错误,错误显示,解决方案?扩展的route.php无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆