首页 > 解决方案 > 使用单个表单将数据保存到两个表

问题描述

我有一个输入餐厅详细信息的表格

@extends('layouts.app')
        @section('content')

        <html>
        <head>

        </head>
        <body>
        <h3 class="text-center"><u>Create Restaurant</u></h3>
        <div class="container">

        {!! Form::open(['action' => 'RestaurantsController@store','method'=>'POST','enctype'=>'multipart/form-data'])!!}
        <div class="form-group">
        {{Form::label('name','Name')}}
        {{Form::text('name','',['class'=>'form-control','placeholder'=>'Insert here'])}}
        </div>
        <div class="form-group">
                {{Form::label('opening_time','Opening time')}}
                {{Form::time('opening time','',['class'=>'form-control','placeholder'=>'Insert here'])}}
                </div>
                <div class="form-group">
                        {{Form::label('closing_time','Closing time')}}
                        {{Form::time('closing time','',['class'=>'form-control','placeholder'=>'Insert here'])}}
                        </div>
                <div class="form-group">
                        {{Form::label('days_of_operation','Days of operation')}}
                        {{Form::text('days_of_operation','',['class'=>'form-control','placeholder'=>'Insert here'])}}
                        </div>
                <div class="form-group">
                        {{Form::label('website','Website')}}
                        {{Form::text('website','',['class'=>'form-control','placeholder'=>'Insert here'])}}
                        </div>


        <div class="form-group">
                {{Form::label('email','Email')}}
                {{Form::text('email',null,['class'=>'form-control','id'=>'menu','placeholder'=>'Insert here'])}}
        </div>
        <div class="form-group">
                        {{Form::label('phone','Phone')}}
                        {{Form::text('phone',null,['class'=>'form-control','id'=>'phone','placeholder'=>'Insert here'])}}
                </div>

                <div class="form-group">
                        {{Form::label('pysical_address','Physical address')}}
                        {{Form::textarea('physical_address','',['class'=>'form-control','placeholder'=>'Insert here'])}}
                        </div>
                        <div class="form-group">
                                {{Form::label('lat','Latitude')}}
                                {{Form::number('lat',null,['class'=>'form-control','id'=>'lat','placeholder'=>'Insert here'])}}
                        </div>
                        <div class="form-group">
                                {{Form::label('lon','Longitude')}}
                                {{Form::number('lon',null,['class'=>'form-control','id'=>'lon','placeholder'=>'Insert here'])}}
                        </div>
        <div class="form-group">
                        {{Form::file('cover_image')}}
        </div>
        {{-- {{Form::hidden('_method','POST')}} --}}
        {{Form::submit('submit',['class'=>'btn btn-primary','type'=>'submit','id'=>'submit'])}}

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


        </div>

        </body>


        </html>

        @endsection

我需要在坐标表中保存纬度、经度、餐厅 ID

我需要在餐厅表中保存以下详细信息

$restaurant=new Restaurant;
        $restaurant->name= $request->input('name');
        $restaurant->opening_time=$request->input('opening_time');
        $restaurant->physical_address=$request->input('physical_address');
        $restaurant->closing_time=$request->input('closing_time');
        $restaurant->days_of_operation=$request->input('days_of_operation');
        $restaurant->website=$request->input('website');
        $restaurant->email=$request->input('email');
        $restaurant->phone=$request->input('phone');
        $restaurant->cover_image=$fileNameToStore;
        $restaurant->save();

我该怎么做?如何查询用户位置附近的餐厅?我知道如何获取当前用户的经度和纬度然后呢?

标签: mysqllaravel

解决方案


推荐阅读