小编dol*_*lar的帖子

如何在Laravel 5.2中存储多选值

我有一个存储新闻的表格.

在此输入图像描述

在这里我使用Multiselect,我想保存表中的所有选定选项,如用户,员工,电影院作为字符串.

我的控制器函数存储值是

 public function store(Request $request)
{

    $input=$request->all();

    General_news::create($input);
    return redirect()->back();
}
Run Code Online (Sandbox Code Playgroud)

此函数存储所有提交的字段,但对于多选,它仅存储最后一个选项,即cinemahall

在此输入图像描述

提交表单时,将显示所有选定的选项,但不会正确保存在数据库表中.

帮我解决这个问题.

php multi-select laravel laravel-5.2

7
推荐指数
1
解决办法
2万
查看次数

如何使用Laravel 5.1在表中保存上传的文件名

我需要帮助使用laravel 5.1在数据库表中保存上传的文件名.

我的Controller代码用于保存图像详细信息

public function store(Request $request)
{
   if($request->hasFile('img_filename'))
   {
       $destinationPath="offerimages";
       $file = $request->file('img_filename');
       $filename=$file->getClientOriginalName();
       $request->file('img_filename')->move($destinationPath,$filename);

   }

    $input=$request->all();
    Offer_image::create($input);
    return redirect('offerimage');
}
Run Code Online (Sandbox Code Playgroud)

我的接受图像的视图代码

{!! Form::open(array('route'=>'offerimage.store','role'=>'form','files'=>true)) !!}
              <div class="box-body">

                <div class="form-group">
                  {!! Form::label('img_name','Name') !!}
                  {!! Form::text('img_name', $value = null, $attributes = array('class'=>'form-control','id'=>'img_name','required')) !!}
                </div>

                <div class="form-group">
                  {!! Form::label('img_description','Description') !!}
                  {!! Form::textarea('img_description', $value = null, $attributes = array('class'=>'form-control','id'=>'img_description','required')) !!}
                </div>

                <div class="form-group">
                  {!! Form::label('img_filename','Upload Image') !!}
                  {!! Form::file('img_filename') !!}
                </div>



                {!! Form::hidden('status',$value='active') !!}

              </div><!-- /.box-body -->

              <div class="box-footer">
                {!! Form::submit('Submit',$attributes=array('class'=>'btn btn-primary')) !!} …
Run Code Online (Sandbox Code Playgroud)

php mysql file-upload laravel laravel-5.1

5
推荐指数
1
解决办法
7264
查看次数

在laravel 5.1中将对象转换为数组

我有这个代码工作正常

 public function success(Request $request)
 {
    $paymentstatus=$request->input('status');
    $transactionid=$request->input('txnid');
    Ticket::where('transactionid',$transactionid)->update(['paymentstatus'=>$paymentstatus]);
    $ticketdata=Ticket::with('eventdetail')->where('transactionid',$transactionid)->first();

    $venuename=$ticketdata->eventdetail->venuename;
    $eventname=$ticketdata->eventdetail->eventname;
    $eventdate=Carbon::parse($ticketdata->eventdetail->eventdate)->format('d M Y');


 $myticketdata=array('ticketid'=>'200','class'=>'gold','no_of_persons'=>'10','fullname'=>'tommy dollar','email'=>'xya@gmail.com','mobile'=>'9874563210','transactionid'=>'alskdjflaskjdflakjd');

   EmailController::sendemail($ticketdata->email,$myticketdata);

    return "success";
}
Run Code Online (Sandbox Code Playgroud)

但我想发送使用下面给定的行获取的数组

$ticketdata=Ticket::with('eventdetail')->where('transactionid',$transactionid)->first();
Run Code Online (Sandbox Code Playgroud)

所以在上面的函数我改变了这一行

EmailController::sendemail($ticketdata->email,$ticketdata);
Run Code Online (Sandbox Code Playgroud)

但执行此代码后,我收到此错误 在此输入图像描述

我知道这个错误是因为我没有将数组传递给此函数,但我无法纠正此代码.我也尝试将对象强制转换为数组,但这在这里没有用.

php mysql arrays laravel laravel-5

4
推荐指数
1
解决办法
3056
查看次数

从laravel 5.1中的多个表中获取多个行数据

在使用laravel 5.1框架处理管理控制面板时,我陷入了项目开发的中期.

我无法从多行的多个表中获取数据.这是我的情景

请检查这张图片是我的桌子结构.

[1] Offer Table - saves all offers
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

[2] Restaurant Table - Saves all restaurant information
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

[3] OfferImage Table - Saves all offers images
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

[4] FoodItem Table - saves all food items
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想要做的是,显示图1中显示的所有优惠,但这样做对我来说非常困难.

这是我的控制器代码

public function index()
{
  $alldata=Offer::all(); //this line is correct 

  $offerimage=Offer_image::all(); //this 3 lines are logically incorrect
  $restaurant=Restaurant::all();
  $fooditem=Food_item::all();
  return view('admin.listoffer',
  compact('alldata','offerimage','restaurant','fooditem'));
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码

@foreach($alldata as $data)  
 <tr role="row" class="odd">
 <td class="sorting_1">{{ $data->offer_id }}</td>
 <td>{{ $offerimage->img_filename }} !!}</td>
 <td>{{ $restaurant->rest_name }}</td>
 <td>{{ …
Run Code Online (Sandbox Code Playgroud)

php mysql laravel laravel-5 laravel-5.1

2
推荐指数
1
解决办法
3554
查看次数

如何从 Laravel 5.2 中的另一个控制器调用控制器函数?

我在 Laravel 5.2 中有 2 个控制器

1) Apiauth 控制器

   <?php

   namespace App\Http\Controllers;

   use Illuminate\Http\Request;

   use App\Http\Requests;
   use App\Api_auth;

   class Apiauth extends Controller
   {
       public function checkauth($reqauthkey)
       {
             $authkey=Api_auth::orderBy('id', 'desc')->first();


             if($authkey->authkey!=$reqauthkey)
            return response()->json(['response'=>'false','message'=>'Authentication Failed','code'=>403],403);  
        }

 }
Run Code Online (Sandbox Code Playgroud)

2) 移动注册控制器

        namespace App\Http\Controllers;


        use Illuminate\Http\Request;
        use App\Http\Controllers\Apiauth;
        use App\Http\Requests;
        use App\Mobile_registration;
        use App\Api_auth;

        use App\Http\Requests\CreateMobileRegistrationRequest;

        class MobileregistrationController extends Controller
        {

            public function index(Request $request)
            {

                App\Http\Controllers\Apiauth->checkauth($request->authkey);

                // $authkey=Api_auth::orderBy('id', 'desc')->first();


                // if($authkey->authkey!=$request->authkey)
                //     return response()->json(['response'=>'false','message'=>'Authentication Failed','code'=>403],403);    

                $mobileregistration=Mobile_registration::all();


                if($mobileregistration->isEmpty())
                    return response()->json(['response'=>'false','message'=>'No data found','code'=>404],404);
                else
                    return response()->json(['response'=>'true','data'=>$mobileregistration],200); …
Run Code Online (Sandbox Code Playgroud)

php api laravel laravel-5

-2
推荐指数
1
解决办法
9758
查看次数