gpt4 book ai didi

casasController.php 第 51 行中的 Laravel 5.2 FatalErrorException

转载 作者:行者123 更新时间:2023-12-04 16:55:57 25 4
gpt4 key购买 nike

我需要你的帮助。我正在 Laravel5.2 中构建一个 webApp。这是我无法解决的问题... casasController.php 第 51 行中的 FatalErrorException ;我真的不知道该怎么做……在命名空间中正确声明了对象,并且一旦验证就保存了!

这是我的 Controller :

    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Oggetto;
use App\Categoria;
use DB;
use Session;

class casasController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$oggetti = DB::table('casas')->get();
$categoriasSelect = DB::table('categorias')->get();
return view('pages.casa')->with('categoriasSelect', $categoriasSelect)->with('oggetti', $oggetti);
}

/**
* 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)
{
$this->validate($request, [
'nome' => 'required',
'categoria' => 'required',
'descrizione' => 'required'
]);

$oggetto = new Oggetto;
$oggetto->nome = $request->nome;
$oggetto->categoria = $request->categoria;
$oggetto->descrizione = $request->descrizione;
$status = $request->nome;

$oggetto->save();

Session::flash('success', 'Il tuo oggetto per la casa è stato salvato con successo!');

return view('pages.casa')->with('oggetto', $oggetto);
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

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

这些是我的路线:
Route::get('/', 'pagesController@index');

Route::group(array('prefix' => 'luogo'), function(){
Route::get('casa',['as' => 'opzione1', 'uses' => 'casasController@index']);
Route::get('parco',['as' => 'opzione2', function(){
return view('pages.parco');
}]);
Route::get('stazione',['as' => 'opzione3', function(){
return view('pages.stazione');
}]);
});
Route::post('nome', ['as' => 'nomeInput', 'uses' => 'pagesController@form']);
//Authentication Routes(login) -->built in
Route::get('auth/login', ['as' => 'login', 'uses' => 'Auth\AuthController@getLogin']);
Route::post('auth/login', ['as' => 'loginPost', 'uses' => 'Auth\AuthController@postLogin']);
Route::get('auth/logout', [ 'as' => 'logout', 'uses' => 'Auth\AuthController@getLogout']);

//Registration Routes(new users) -->built in
Route::get('auth/register', ['as' => 'register', 'uses' => 'Auth\AuthController@getRegister']);
Route::post('auth/register', 'Auth\AuthController@postRegister');

Route::post('categoria', ['as' => 'categ', 'uses' => 'categoriasController@newCat']);
Route::resource('oggetto/{status?}', 'casasController', ['except' => ['show']]);

这是我的观点:
@extends('main')

@section('content')

<h1 class="text-center">Benvenuto a Casa</h1>
<h3 class="text-center"><a href="" id="link_formOggetto"> Aggiungi un oggetto</a></h3>
<div class="row">
<div class="col-md-8 col-md-offset-2">
@if(count($errors) > 0)
@foreach($errors->all() as $error)
<div class="alert alert-danger">{{$error}}</div>
@endforeach
@elseif(Session::has('success'))
<div class="alert alert-success">{{Session::get('success')}}</div>
@endif
<table class="table table-striped">
<thead>
<tr>
<th>Nome</th>
<th>Categoria</th>
<th>Descrizione</th>
<th colspan="2">Azioni</th>
</tr>
</thead>
<tbody>
@foreach($oggetti as $oggetto)
<tr>
<td>{{$oggetto->nome}}</td>

<td>{{$oggetto->categoria}}</td>

<td>{{$oggetto->descrizione}}</td>
<td><button type="button" class="btn btn-info btn-block">Editare</button></td>
<td><button type="button" class="btn btn-danger btn-block">Cancellare</button></td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="row" id="formOggetto" style="display: none; margin-top: 25px">
<div class="col-md-8 col-md-offset-2">
<form action="{{action('casasController@store')}}" method="POST">
<input type="hidden" name="_token" value="{{csrf_token()}}"/>
<div class="form-group">
<label for="nome">Nome</label>
<input type="text" class="form-control" id="nome" name="nome" placeholder="Nome">
</div>
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label for="categoria">Categoria</label>
<select class="form-control" name="categoria">
<option value="null">Scegli...</option>
@foreach($categoriasSelect as $categoriaSelect)
<option>{{$categoriaSelect->nome}}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-4">
<label>Aggiungi nuova categoria</label>
<button type="button" class="btn btn-warning btn-block" data-toggle="modal" data-target="#modalCateg">Aggiungi</button>
</div>
</div>
<div class="form-group">
<label for="descrizione">Descrizione</label>
<textarea type="text" class="form-control" id="descrizione" name="descrizione" placeholder="Descrizione"></textarea>
</div>
<input type="submit" class="btn btn-primary btn-block" value="Salva">
</form>
</div>
</div>
@stop

最佳答案

好的,您没有 Oggetto 模型,因此您需要先创建它。

也改变这个:

$oggetto = new Oggetto;

对此:
$oggetto = new Oggetto();

关于casasController.php 第 51 行中的 Laravel 5.2 FatalErrorException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37006939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com