dongyun3335 2018-01-28 06:39
浏览 31
已采纳

无法从Laravel表单存储有关DB的信息

I have this application using Laravel and im trying to register some information from the Form Class to my DB through the store method in the controller, but for some reason it throws me some error. I cant even print the request coming from the form, as usual. Can someone point me a possible mistake tht i am making? I am new to Laravel

This is my form on a view called create.blade.php

@extends('layouts.app')


@section('content')



    <p><b>Register your house</b></p>


            {!! Form::open(['method'=>'post', 'action'=>'AdminHouseController@store']) !!}

                {!! Form::text('house_address', null,['placeholder'=>'House Address']) !!}

                <input type="hidden" name="house_admin" value="{{Auth::user()->id}}">

                {!! Form::number('nflatmates', null, ['placeholder'=>'How many flatmates']) !!}

                {!! Form::submit('Register', ['class'=>'ui-btn buttonDefault']) !!}

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




@stop

This is my controller AdminHouseController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\House;
use App\User;

class AdminHouseController extends Controller
{

    public function index(){




    }


    public function create($role_id){

        if($role_id == 1){

            return view('admin.house.create');

        }else{

            return redirect('home');

        }

    }


    public function store(Request $request){

        House::create($request->all());

        return redirect('home');

    }

    public function show($id){

    }

    public function edit($id){

    }

    public function update(Request $request, $id){

    }

    public function destroy($id){

    }
}

And this is my router file web.php

use App\User;

Route::get('/', function () {
    return view('welcome');
});


Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/house/{role_id}', 'AdminHouseController@create')->name('house');

Route::post('store', [
    'uses' => 'AdminHouseController@store'
]);

展开全部

  • 写回答

1条回答 默认 最新

  • dongxiong4571 2018-01-28 09:40
    关注

    you might be missing the {{ csrf_field() }} in the form this used to protect the form from tampering

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥40 selenium访问信用中国
  • ¥15 电视大赛投票系统的c语言代码怎么做
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?
  • ¥15 ctrl win alt 键一直触发
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部