jsanwo64

jsanwo64

Member Since 3 Years Ago

Lagos

Experience Points 720
Experience Level 1

4,280 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

18 Sep
2 days ago

jsanwo64 left a reply on How Many Middleware Am I Allowed To Include In The Get Method Of The Routes.

i am getting this error

 [Symfony\Component\Debug\Exception\FatalThrowableError]
  Type error: Argument 2 passed to Illuminate\Routing\Controller::middleware() must be of the type array, string given, called in C:\xampp\htdocs\laravel-practice\ap
  p\Http\Controllers\StaffController.php on line 14

jsanwo64 left a reply on How Many Middleware Am I Allowed To Include In The Get Method Of The Routes.

is this also correct

  public function __construct()
    {
        $this->middleware('isRn' 'isSw');
    }

jsanwo64 started a new conversation How Many Middleware Am I Allowed To Include In The Get Method Of The Routes.


Route::get('/user/profile', '[email protected]')->name('user.profile')->middleware('isRn','isSw');

Route::get('/user/applications', '[email protected]')->name('user.applications')->middleware('isSw','isRn');
11 Sep
1 week ago

jsanwo64 left a reply on What Am I Doing Wrong

@punksolid I Have menu which is a drop down with the following items, home care, specialist care and support living, now if I am on any of those page I need the menu holding them item to have a class named current eg class="current"

jsanwo64 started a new conversation What Am I Doing Wrong

   @if(Request::path() == 'support-living')  
       <li class="current"><a href="#">Care Services</a>
                                        <ul>
                                            <li><a href="respite-care.html">Home Care</a></li>
                                            <li><a href="personal-care.html">Specialist Care</a></li>
                                            <li><a href="elderly-service.html">Supported Living</a></li>
                                        </ul>
                                    </li>     
                                    @elseif(Request::path() == 'home-care')  
 <li class="current"><a href="#">Care Services</a>
                                        <ul>
                                            <li><a href="respite-care.html">Home Care</a></li>
                                            <li><a href="personal-care.html">Specialist Care</a></li>
                                            <li><a href="elderly-service.html">Supported Living</a></li>
                                        </ul>
                                    </li>      
@elseif(Request::path() == 'specialist-care')  
 <li class="current"><a href="#">Care Services</a>
                                        <ul>
                                            <li><a href="respite-care.html">Home Care</a></li>
                                            <li><a href="personal-care.html">Specialist Care</a></li>
                                            <li><a href="elderly-service.html">Supported Living</a></li>
                                        </ul>
                                    </li>  
@endif
06 Nov
10 months ago

jsanwo64 started a new conversation SQLSTATE[HY000]: General Error: 1364 Field 'image' Doesn't Have A Default Value

Every other get fetched except that of the image,

here is the error i get

SQLSTATE[HY000]: General error: 1364 Field 'image' doesn't have a default value (SQL: insert into `room_type` (`hotel_name`, `room_name`, `occupants`, `price`, `updated_at`, `created_at`) values (The Manhattan at Times Square, Sample room, ["fas fa-user","fas fa-user"], 90,000.00, 2018-11-06 10:16:07, 2018-11-06 10:16:07))

here is my controller

public function post_room_type(Request $request)
    {
            
            $validator = Validator::make($request->all(), [
             'hotel_name'  => 'required',
             'room_name'   => 'required',
             'image'       => 'required',
             'occupants'   => 'required',
             'price'       => 'required',
             ]);

       if ($validator->fails()) {
           return redirect('/admin/hotels/create-room-type')
                    ->withErrors($validator)
                    ->withInput(); 
       }else {

        $add_room_type                       = new Roomtype;

        

        $add_room_type->hotel_name           = $request->input('hotel_name');
        $add_room_type->room_name             = $request->input('room_name');

if($request->hasFile('image')){
           $image = $request->file('image');
           $filename = time() . '.' . $image->getClientOriginalExtension();
           Image::make($image)->resize(350, 232)->save( public_path('uploads/Hotels/room' . $filename));
             $add_room_type->image = $filename;

     }
        
        $add_room_type->occupants             = $request->input('occupants');
        $add_room_type->price             = $request->input('price');



        $add_room_type->save();


   return back()->with('message', 'Room type added successfully!!!');

       }

    }

here is my view

<form id="demo-form2" data-parsley-validate class="form-horizontal form-label-left" action="/admin/hotels/create-room-type" method="post">
  {{ csrf_field() }}
                      <div class="form-group{{ $errors->has('hotel_name') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Hotel Name <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                         <select class="select2_single form-control" tabindex="-1" required="required" name="hotel_name">
            
                                  @foreach($catch as $caught)
                       <option value=""></option>
                      <option value="{{$caught->hotel_name}}">{{$caught->hotel_name}}</option>
                     
                       @endforeach
                       </select>
                          @if ($errors->has('hotel_name'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('hotel_name') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>
                      <div class="form-group{{ $errors->has('room_name') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Room name</label>

                        <div class="col-md-6 col-sm-6 col-xs-12">
                            
                            <select class="select2_single form-control" tabindex="-1" required="required" name="room_name">
            
                                          @foreach($catch as $caught)
                                           <option value=""></option>
                                         <option value="{{$caught->room_name}}">{{$caught->room_name}}</option>
                     
                                               @endforeach
                              </select>

                          @if ($errors->has('room_name'))
                                                                <span class="help-block">
                                                                    <strong>{{ $errors->first('room_name') }}</strong>
                                                                </span>
                                                            @endif
                        </div>
                      </div>


                       <div class="form-group{{ $errors->has('image') ? ' has-error' : '' }}">
                        <label for="middle-name" class="control-label col-md-3 col-sm-3 col-xs-12"> Room image</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input type="file" id="middle-name" required="required" class="form-control col-md-7 col-xs-12" name="image">
                          @if ($errors->has('image'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('image') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>
                     

                       <div class="form-group{{ $errors->has('occupants') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Occupant(s)</label>

                    <div class="col-md-6 col-sm-6 col-xs-12">
                      <select class="select2_single form-control" tabindex="-1" required="required" name="occupants[]" multiple>
                        <option value=""></option>
                        <option value="fas fa-user">fas fa-user</option>
                        <option value="fas fa-user">fas fa-user</option>
                        <option value="fas fa-user">fas fa-user</option>
                      </select>
                          @if ($errors->has('occupants'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('occupants') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>

                       <div class="form-group{{ $errors->has('price') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Price</label>

                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <input id="middle-name" required="required" class="form-control col-md-7 col-xs-12" type="text" name="price">
                          @if ($errors->has('price'))
                                                                <span class="help-block">
                                                                    <strong>{{ $errors->first('price') }}</strong>
                                                                </span>
                                                            @endif
                        </div>
                      </div>

                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                          <button type="submit" class="btn btn-primary">Cancel</button>
                          <button type="submit" class="btn btn-success">Submit</button>
                        </div>
                      </div>

                    </form>

and here is my model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Roomtype extends Model
{
     protected $table = 'room_type';

    protected $casts = [

         'occupants' => 'array',
        
    ]; 

    protected $fillable = [
        'hotel_name', 'image',
    ]; 

}

is there something im doing wrong in the model?

27 Oct
10 months ago

jsanwo64 left a reply on Return Array Data Rom Database To View

@Snapey thanks a lot, it works!!!!

jsanwo64 left a reply on Store Array Data In Database Table

@tykus the json_decode() is not of it just overlook it cos wit or without I still get the same result in the view, I will try your last post and get back to you. Thanks

jsanwo64 left a reply on Return Array Data Rom Database To View

@Snapey when in dd here is what i get

Collection {#592 ▼
  #items: array:1 [▼
    0 => {#590 ▼
      +"id": 1
      +"hotel_name": "The Manhattan at Times Square"
      +"bathroom": "["Toilet paper","Linen"]"
      +"internet": "Free wifi"
      +"cleaning_services": "["Daily maid service","Shoeshine"]"
      +"general": "["ATM On Site","Air conditioning"]"
      +"pool_and_wellness": "["Massage","Fitness centre"]"
      +"biz_facilities": "["Fax\/photocopying","Fitness centre"]"
      +"parking": "Parking space available"
      +"food_and_drink": "["Breakfast in the room","Bar"]"
      +"reception_services": "["Concierge service","Luggage storage"]"
      +"media_and_technology": "["Radio","Telephone"]"
      +"payment_type": "["Cash","Debit\/Credit Card"]"
      +"check_in": "15:00"
      +"check_out": "15:00"
      +"created_at": "2018-10-27 02:06:35"
      +"updated_at": "2018-10-27 02:06:35"
    }
  ]
}

jsanwo64 started a new conversation Return Array Data Rom Database To View

Data are stored as ["item_1", "item_2"] in database.

I want to display those data in view blade properly.

i tried this

 @foreach(json_decode($fac) as $faci)
                              <li>{{ $faci->bathroom }}</li>
  @endforeach

but ended up getting this in the view

["Toilet paper","Linen"]

here is my controller

$fac = DB::table('hotel_facilities')->where('hotel_name', $name)->get();
return view('admin/hotels/show', compact('catch', 'images', 'fac'))->withTask($user);
26 Oct
10 months ago

jsanwo64 left a reply on Store Array Data In Database Table

@tykus Data are stored as ["item_1", "item_2"] in database.

I want to display those data in view blade properly.

i tried this

 @foreach(json_decode($fac) as $faci)
                              <li>{{ $faci->bathroom }}</li>
  @endforeach

but ended up getting this in the view

["Toilet paper","Linen"]

here is my controller

$fac = DB::table('hotel_facilities')->where('hotel_name', $name)->get();
return view('admin/hotels/show', compact('catch', 'images', 'fac'))->withTask($user);

jsanwo64 started a new conversation Store Array Data In Database Table

i have a form which has multiple option , when i dd($request->all()) i get the results but storing the array to database is where am having problem. below is the form

 <form id="demo-form2" data-parsley-validate class="form-horizontal form-label-left" action="/admin/hotels/add_facilities" method="post">
  {{ csrf_field() }}
                      <div class="form-group{{ $errors->has('hotel_name') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Hotel Name <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                         <select class="select2_single form-control" tabindex="-1" required="required" name="hotel_name">
            @foreach($catch as $caught)
             <option value=""></option>
                      <option value="{{$caught->hotel_name}}">{{$caught->hotel_name}}</option>
                      @endforeach
                    </select>
                      @if ($errors->has('hotel_name'))
                        <span class="help-block">
                            <strong>{{ $errors->first('hotel_name') }}</strong>
                        </span>
                    @endif
                  </div>
                      </div>
                      <div class="form-group{{ $errors->has('bathroom') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Bathroom</label>

                <div class="col-md-6 col-sm-6 col-xs-12">
                  <select class="select2_single form-control" tabindex="-1" required="required" name="bathroom[]" multiple>
                    <option value=""></option>
                    <option value="Toilet paper">Toilet paper</option>
                    <option value="Linen">Linen</option>
                    <option value="Towels">Towels</option>
                    <option value="Toilet">Toilet</option>
                    <option value="Free toiletries">Free toiletries</option>
                    <option value="Hairdryer">Hairdryer</option>
                  </select>
                          @if ($errors->has('bathroom'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('bathroom') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>
                      <div class="form-group{{ $errors->has('internet') ? ' has-error' : '' }}">
                        <label for="middle-name" class="control-label col-md-3 col-sm-3 col-xs-12">Internet</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
     <input id="middle-name" required="required" class="form-control col-md-7 col-xs-12" type="text" name="internet">
                          @if ($errors->has('internet'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('internet') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>


                      <div class="form-group{{ $errors->has('cleaning_services') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Cleaning services</label>

                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <select class="select2_single form-control" tabindex="-1" required="required" name="cleaning_services[]" multiple>
                          <option value=""></option>
                          <option value="Daily maid service">Daily maid service</option>
                          <option value="Shoeshine">Shoeshine</option>
                          <option value="Ironing service">Ironing service</option>
                          <option value="Dry cleaning">Dry cleaning</option>
                          <option value="Laundry">Laundry</option>
                        </select>
                          @if ($errors->has('cleaning_services'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('cleaning_services') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>



                      <div class="form-group{{ $errors->has('general') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">General</label>

                        <div class="col-md-6 col-sm-6 col-xs-12">
                    <select class="select2_single form-control" tabindex="-1" required="required" name="general[]" multiple>
                      <option value=""></option>
                      <option value="ATM On Site">ATM On Site</option>
                      <option value="Air conditioning">Air conditioning</option>
                      <option value="Ironing service">Wake-up service</option>
                      <option value="Heating">Heating</option>
                      <option value="24h Electricity">24h Electricity</option>
                      <option value="Lift">Lift</option>
                      <option value="Car Hire">Car Hire</option>
                      <option value="Security(Guarded Complex)">Security(Guarded Complex)</option>
                    </select>
                          @if ($errors->has('general'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('general') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>



                      <div class="form-group{{ $errors->has('pool_and_wellness') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Pool and wellness</label>

                    <div class="col-md-6 col-sm-6 col-xs-12">
                      <select class="select2_single form-control" tabindex="-1" required="required" name="pool_and_wellness[]" multiple>
                        <option value=""></option>
                        <option value="Massage">Massage</option>
                        <option value="Fitness centre">Fitness centre</option>
                        <option value="Ironing service">Sauna</option>
                        <option value="Swimming pool">Swimming pool</option>
                      </select>
                          @if ($errors->has('pool_and_wellness'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('pool_and_wellness') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>


                <div class="form-group{{ $errors->has('biz_facilities') ? ' has-error' : '' }}">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">Business facilities</label>

                  <div class="col-md-6 col-sm-6 col-xs-12">
                    <select class="select2_single form-control" tabindex="-1" required="required" name="biz_facilities[]" multiple>
                      <option value=""></option>
                      <option value="Fax/photocopying">Fax/photocopying</option>
                      <option value="Fitness centre">Fitness centre</option>
                      <option value="Business centre">Business centre</option>
                      <option value="Swimming pool">Meeting/banquet facilities</option>
                    </select>
                    @if ($errors->has('biz_facilities'))
                        <span class="help-block">
                            <strong>{{ $errors->first('biz_facilities') }}</strong>
                        </span>
                    @endif
                      </div>
                      </div>

                <div class="form-group{{ $errors->has('parking') ? ' has-error' : '' }}">
                  <label for="middle-name" class="control-label col-md-3 col-sm-3 col-xs-12">Parking</label>
                  <div class="col-md-6 col-sm-6 col-xs-12">
                    <input id="middle-name" required="required" class="form-control col-md-7 col-xs-12" type="text" name="parking">
                    @if ($errors->has('parking'))
                        <span class="help-block">
                            <strong>{{ $errors->first('parking') }}</strong>
                        </span>
                    @endif
                  </div>
                </div>


                      <div class="form-group{{ $errors->has('food_and_drink') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Food and Drink</label>

                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select class="select2_single form-control" tabindex="-1" required="required" name="food_and_drink[]" multiple>
                            <option value=""></option>
                            <option value="Breakfast in the room">Breakfast in the room</option>
                            <option value="Bar">Bar</option>
                            <option value="Restaurant">Restaurant</option>
                            <option value="Tea/Coffee maker">Tea/Coffee maker</option>
                          </select>
                          @if ($errors->has('food_and_drink'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('food_and_drink') }}</strong>
                                </span>
                          @endif
                        </div>
                      </div>

                      <div class="form-group{{ $errors->has('reception_services') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Reception services</label>

                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select class="select2_single form-control" tabindex="-1" required="required" name="reception_services[]" multiple>
                            <option value=""></option>
                            <option value="Concierge service">Concierge service</option>
                            <option value="Luggage storage">Luggage storage</option>
                            <option value="Ticket service">Ticket service</option>
                            <option value="Express check-in/check-out">Express check-in/check-out</option>
                            <option value="24-hour front desk">24-hour front desk</option>
                          </select>
                          @if ($errors->has('reception_services'))
                                                                <span class="help-block">
                                                                    <strong>{{ $errors->first('reception_services') }}</strong>
                                                                </span>
                                                            @endif
                        </div>
                      </div>




                      <div class="form-group{{ $errors->has('media_and_technology') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Media and technology</label>

                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select class="select2_single form-control" tabindex="-1" required="required" name="media_and_technology[]" multiple>
                            <option value=""></option>
                            <option value="iPod dock">iPod dock</option>
                            <option value="Cable channels(DSTV)">Cable channels(DSTV)</option>
                            <option value="Radio">Radio</option>
                            <option value="Telephone">Telephone</option>
                            <option value="TV">TV</option>
                          </select>
                          @if ($errors->has('media_and_technology'))
                                                                <span class="help-block">
                                                                    <strong>{{ $errors->first('media_and_technology') }}</strong>
                                                                </span>
                                                            @endif
                        </div>
                      </div>


                      <div class="form-group{{ $errors->has('payment_type') ? ' has-error' : '' }}">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">Payment Type</label>

                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select class="select2_single form-control" tabindex="-1" required="required" name="payment_type[]" multiple>
                            <option value=""></option>
                            <option value="Cash">Cash</option>
                            <option value="Debit/Credit Card">Debit/Credit Card</option>
                          </select>
                          @if ($errors->has('payment_type'))
                                                                <span class="help-block">
                                                                    <strong>{{ $errors->first('payment_type') }}</strong>
                                                                </span>
                                                            @endif
                        </div>
                      </div>

                      <div class="form-group{{ $errors->has('check_in') ? ' has-error' : '' }}">
                        <label for="middle-name" class="control-label col-md-3 col-sm-3 col-xs-12">Check-in</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
     <input id="middle-name" required="required" class="form-control col-md-7 col-xs-12" type="text" name="check_in">
                          @if ($errors->has('check_in'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('check_in') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>


<div class="form-group{{ $errors->has('check_out') ? ' has-error' : '' }}">
                        <label for="middle-name" class="control-label col-md-3 col-sm-3 col-xs-12">Check-out</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
     <input id="middle-name" required="required" class="form-control col-md-7 col-xs-12" type="text" name="check_out">
                          @if ($errors->has('check_out'))
                              <span class="help-block">
                                  <strong>{{ $errors->first('check_out') }}</strong>
                              </span>
                          @endif
                        </div>
                      </div>


                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                          <button type="submit" class="btn btn-primary">Cancel</button>
                          <button type="submit" class="btn btn-success">Submit</button>
                        </div>
                      </div>

                    </form>

here is the controller

public function post_add_facilities(Request $request)
    {
            
            $validator = Validator::make($request->all(), [
             'hotel_name' => 'required',
             'bathroom' => 'required',
             'internet' => 'required',
             'cleaning_services' => 'required',
             'general' => 'required',
             'pool_and_wellness' => 'required',
             'biz_facilities' => 'required',
             'parking' => 'required',
             'food_and_drink' => 'required',
             'reception_services' => 'required',
             'media_and_technology' => 'required',
             'payment_type' => 'required',
             'check_in' => 'required',
             'check_out' => 'required',
             ]);

       if ($validator->fails()) {
           return redirect('/admin/hotels/add_facilities')
                    ->withErrors($validator)
                    ->withInput(); 
       }else {

        $add_hotel_facilities                       = new Hotelfacilities;
        $add_hotel_facilities->hotel_name           = $request->input('hotel_name');
        $add_hotel_facilities->bathroom             = $request->input('bathroom');
        $add_hotel_facilities->internet             = $request->input('internet');
        $add_hotel_facilities->cleaning_services    = $request->input('cleaning_services');
        $add_hotel_facilities->general              = $request->input('general[]');
        $add_hotel_facilities->pool_and_wellness    = $request->input('pool_and_wellness');
        $add_hotel_facilities->biz_facilities       = $request->input('biz_facilities');
        $add_hotel_facilities->parking              = $request->input('parking');
        $add_hotel_facilities->food_and_drink       = $request->input('food_and_drink');
        $add_hotel_facilities->reception_services   = $request->input('reception_services');
        $add_hotel_facilities->media_and_technology = $request->input('media_and_technology');
        $add_hotel_facilities->payment_type         = $request->input('payment_type');
        $add_hotel_facilities->check_in             = $request->input('check_in');
        $add_hotel_facilities->check_out            = $request->input('check_out');
        $add_hotel_facilities->save();


   return back()->with('message', 'Hotel facilities  added successfully!!!');

       }

    }

is there something am doing wrong.

19 Oct
11 months ago

jsanwo64 left a reply on How To Display Multiple Images From Database To Blade View.

here is what i did

public function show ($name)
{

  $catch = DB::table('hotels')->where('hotel_name', $name)->get();
  $user = Hotels::wherehotel_name($name)->firstOrFail();
  $imge = DB::table('hotel_slider')->where('hotel_name', $name)->pluck('file');


 foreach ($imge as $key) {
        
        $images = explode(',', $key);
  }
    return view('admin/hotels/show', compact('catch', 'images'))->withTask($user);
}

and for the view i had this

@foreach($images as $img)

              <img src="/uploads/Hotels/Slider/{{$img}}"  alt="Image Alternative text" title="Image Title"/>
                    
                        @endforeach

jsanwo64 left a reply on How To Display Multiple Images From Database To Blade View.

@click here is the store function

public function post_slider_images(Request $request)
    {

        $validator = Validator::make($request->all(), [
             'name' => 'required',
             'file' => 'required',
             ]);

       if ($validator->fails()) {
           return redirect('/admin/hotels/add_slider_images')
                       ->withErrors($validator)
                       ->withInput();
       }else {

        $files=[];

foreach ($request->file('file') as $media) {
    if (!empty($media)) {
        $destinationPath = 'uploads/Hotels/Slider';
        $filename = $media->getClientOriginalName();
        $media->move($destinationPath, $filename);

        $files[] = $filename;
    }
}
$tour_detail = new Hotelslider;
$tour_detail->file = implode(',',$files);

$tour_detail->hotel_name = $request->input('name');;

$tour_detail->save();   

    }
}

jsanwo64 left a reply on How To Display Multiple Images From Database To Blade View.

@Cronix when i do this

@foreach($images as $img)

              <img src="/uploads/Hotels/Slider/<?php echo($img)  ?>"  alt="Image Alternative text" title="Image Title"/>
                    
                        @endforeach

i get

<img src="/uploads/Hotels/Slider/["action-adventure-blur-386009.jpg"  alt="Image Alternative text" title="Image Title"/>
                    
                        
              <img src="/uploads/Hotels/Slider/almonds-berries-blackberries-1099680.jpg"  alt="Image Alternative text" title="Image Title"/>
                    
                        
              <img src="/uploads/Hotels/Slider/antipasti-delicious-dinner-5876.jpg"]"  alt="Image Alternative text" title="Image Title"/>

in which only two images loads perfectly well

jsanwo64 left a reply on How To Display Multiple Images From Database To Blade View.

@Cronix this what am still getting

 <img src="http://localhost:8000/uploads/Hotels/Sliders/[&quot;action-adventure-blur-386009.jpg" alt="Image Alternative text" title="Image Title"/>
                    
                        
              <img src="http://localhost:8000/uploads/Hotels/Sliders/almonds-berries-blackberries-1099680.jpg" alt="Image Alternative text" title="Image Title"/>
                    
                        
              <img src="http://localhost:8000/uploads/Hotels/Sliders/antipasti-delicious-dinner-5876.jpg&quot;]" alt="Image Alternative text" title="Image Title"/>


am still getting this

 [&quot;  and &quot;]

jsanwo64 left a reply on How To Display Multiple Images From Database To Blade View.

@Cronix i got that

Collection {#566 ▼
  #items: array:1 [▼
    0 => "action-adventure-blur-386009.jpg,almonds-berries-blackberries-1099680.jpg,antipasti-delicious-dinner-5876.jpg"
  ]
}

jsanwo64 left a reply on How To Display Multiple Images From Database To Blade View.

@Borisu reason why I did an explode was because the images in the column "File" is an array which looks like this "a.jpg","b.jpg","c.jpg". The only was I could make them separate was when I did the explode.

 <img src="http://localhost:8000/uploads/Hotels/Sliders/[&quot;action-adventure-blur-386009.jpg" alt="Image Alternative text" title="Image Title"/>
            
                
      <img src="http://localhost:8000/uploads/Hotels/Sliders/almonds-berries-blackberries-1099680.jpg" alt="Image Alternative text" title="Image Title"/>
            
                
      <img src="http://localhost:8000/uploads/Hotels/Sliders/antipasti-delicious-dinner-5876.jpg&quot;]" alt="Image Alternative text" title="Image Title"/>

jsanwo64 left a reply on How To Display Multiple Images From Database To Blade View.

@Borisu I will try that and get back to you. Thanks

jsanwo64 started a new conversation How To Display Multiple Images From Database To Blade View.

i have images saved to the database table, now i try using the the explode funtion to fetch the images to the view

for the view i have this

@foreach($images as $img)

 <img src="{{ URL::to('uploads/Hotels/Sliders/'.$img)}}" alt="Image Alternative text" title="Image Title"/>
                    
 @endforeach

for the controller i have this

 $imge = DB::table('hotel_slider')->where('hotel_name', $name)->pluck('file');

  $images = explode('|', $imge);

but when i try to view the page in browser i get this

          <img src="http://localhost:8000/uploads/Hotels/Sliders/[&quot;action-adventure-blur-386009.jpg" alt="Image Alternative text" title="Image Title"/>
                
                    
          <img src="http://localhost:8000/uploads/Hotels/Sliders/almonds-berries-blackberries-1099680.jpg" alt="Image Alternative text" title="Image Title"/>
                
                    
          <img src="http://localhost:8000/uploads/Hotels/Sliders/antipasti-delicious-dinner-5876.jpg&quot;]" alt="Image Alternative text" title="Image Title"/>

if you check you'd see this quote [" and this "] which am kind of confused at what am doing wrong.

29 Apr
1 year ago

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@Snapey trust me i have been staring at the form for some time now i can't seem to fathom where d array error is coming from now it only returns question_id as 3,3,3 instead of 1,2,3 and when i view the form in the webpage i get it returned as 1,2,3 but when i submit to database i get 3,3,3 i'm lost . here is what my form looks like

<form method="post" action="/submit_quiz" id="quiz_form" >
    
{{ csrf_field() }}
            <b> Questions</b>
    <div style="max-height:60%;overflow-y:auto;">

@foreach($answers as $key => $answer)

<input type="hidden" name="name" value="{{Auth::user()->name}}">
<input type="hidden" name="category" value="{{$answer->category}}">
<input type="hidden" name="year" value="{{$answer->year}}">

<input type="hidden" name="question_id" value="{{$question->id}}">
            <P>{{$answer->id}}.<BR>
                <select name="answer[]">
                    <option></option>
                    <option value="{{$answer->option_A}}">{{$answer->option_A}}</option>
                    <option value="{{$answer->option_B}}">{{$answer->option_B}}</option>
                    <option value="{{$answer->option_C}}">{{$answer->option_C}}</option>
                    <option value="{{$answer->option_D}}">{{$answer->option_D}}</option>
                    <option value="{{$answer->option_E}}">{{$answer->option_E}}</option>
                </select>
</p>
<br>
@endforeach
<button class="btn btn-danger"  onClick="javascript:cancelmove();" style="margin-top:2px;" >Submit Quiz</button>


    
<br>
<br>
<br>

</form>

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@Snapey i did a serialize on question_id

 foreach ( $request->answer as $answer) {
    Answers::create([
        'username' => Auth::user()->name,
        'category' => $request->category,
        'year' => $request->year,
        'correct_answer' => $answer,
        'question_id' => serialize($request->question_id),
    ]);

i get this in the database

a:3:{i:1;s:1:"1";i:2;s:1:"2";i:3;s:1:"3";}

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@Snapey

Whoops, looks like something went wrong.
2/2
QueryException in Connection.php line 770:
Array to string conversion (SQL: insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (jimmy sanwo, WAEC, 1988, 2020, 1))
in Connection.php line 770
at Connection->runQueryCallback('insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3')), object(Closure)) in Connection.php line 726
at Connection->run('insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3')), object(Closure)) in Connection.php line 481
at Connection->statement('insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3'))) in Connection.php line 435
at Connection->insert('insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3'))) in Builder.php line 2138
at Builder->insert(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3'))) in Builder.php line 1470
at Builder->__call('insert', array(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3')))) in Model.php line 3561
at Builder->insert(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3'))) in Model.php line 3561
at Model->__call('insert', array(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3')))) in Model.php line 3573
at Answers->insert(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3'))) in Model.php line 3573
at Model::__callStatic('insert', array(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3')))) in QuizController.php line 78
at Answers::insert(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3'))) in QuizController.php line 78
at QuizController->submit_quiz(object(Request))
at call_user_func_array(array(object(QuizController), 'submit_quiz'), array(object(Request))) in Controller.php line 55
at Controller->callAction('submit_quiz', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(QuizController), 'submit_quiz') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 653
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 655
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\xampp\htdocs\testp\public\index.php') in server.php line 21
1/2
ErrorException in MySqlConnection.php line 81:
Array to string conversion
in MySqlConnection.php line 81
at HandleExceptions->handleError('8', 'Array to string conversion', 'C:\xampp\htdocs\testp\vendor\laravel\framework\src\Illuminate\Database\MySqlConnection.php', '81', array('statement' => object(PDOStatement), 'bindings' => array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3')), 'key' => '4', 'value' => array('1', '2', '3')))
at PDOStatement->bindValue('5', array('1', '2', '3'), '2') in MySqlConnection.php line 81
at MySqlConnection->bindValues(object(PDOStatement), array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3'))) in Connection.php line 478
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3'))) in Connection.php line 763
at Connection->runQueryCallback('insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3')), object(Closure)) in Connection.php line 726
at Connection->run('insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3')), object(Closure)) in Connection.php line 481
at Connection->statement('insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3'))) in Connection.php line 435
at Connection->insert('insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (?, ?, ?, ?, ?)', array('jimmy sanwo', 'WAEC', '1988', '2020', array('1', '2', '3'))) in Builder.php line 2138
at Builder->insert(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3'))) in Builder.php line 1470
at Builder->__call('insert', array(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3')))) in Model.php line 3561
at Builder->insert(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3'))) in Model.php line 3561
at Model->__call('insert', array(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3')))) in Model.php line 3573
at Answers->insert(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3'))) in Model.php line 3573
at Model::__callStatic('insert', array(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3')))) in QuizController.php line 78
at Answers::insert(array('username' => 'jimmy sanwo', 'category' => 'WAEC', 'year' => '1988', 'correct_answer' => '2020', 'question_id' => array('1', '2', '3'))) in QuizController.php line 78
at QuizController->submit_quiz(object(Request))
at call_user_func_array(array(object(QuizController), 'submit_quiz'), array(object(Request))) in Controller.php line 55
at Controller->callAction('submit_quiz', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(QuizController), 'submit_quiz') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 653
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 655
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54
at require_once('C:\xampp\htdocs\testp\public\index.php') in server.php line 21

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@Snapey yes it does, below is my my Migration

public function up()
    {
  Schema::create('user_answers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username');
            $table->string('category');
            $table->string('year');
            $table->string('question_id');
            $table->string('correct_answer');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_answers');
    }

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@Snapey i have added them into the model $fillable array ,i will do the validation of the form once am able to test that the inputs submits successfully to database, after adding them to the model $fillable i get this error

Array to string conversion (SQL: insert into `user_answers` (`username`, `category`, `year`, `correct_answer`, `question_id`) values (jimmy sanwo, WAEC, 1988, 2020, 1))

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@Snapey i tried this

public function submit_quiz(Request $request)
{

 foreach ( $request->answer as $answer) {
    Answers::create([
        'username' => Auth::user()->name,
        'category' => $request->category,
        'year' => $request->year,
        'correct_answer' => $answer,
        'question_id' => $request->question_id,
    ]);
}

i get null for the following columns username, year and question_id

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

with this

public function submit_quiz(Request $request)
{


    $answer = new Answers;

$data = $request->all();
 foreach ( $request->get('answer') as $answer) {
    $answers[] = [
        'username' => Auth::user()->name,
        'category' => $request->category,
        'year' => $request->year,
        'correct_answer' => $answer,
        'question_id' => $request->question_id,
    ];
}
 Answers::insert($answers);

the data get submitted to the database but one error i get the created_at and updated at column returns null also the question id returns the exact figure 3 for each answers submitted instead of 1,2,3 i get 3,3,3

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@cronix for

Answers::insert([$answers]);

i get the error

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into `user_answers` (`0`, `1`, `2`) values (jimmy sanwo, jimmy sanwo, jimmy sanwo))

28 Apr
1 year ago

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@cronix it does not work instead i get

Undefined variable: anwsers

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@amk it returns just one correct answer if i do a dd

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

"question_id" => "3" for each answer instead of the actually question id as it in database

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@amk it submits NULL to database

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

@indpurvesh it works but when i try to submit to database i get this error


ErrorException in MySqlConnection.php line 81:
Array to string conversion

i used Answers::insert($answers); to submit to the database

this is what the dd($answers) returns

array:3 [▼
  0 => array:5 [▼
    "username" => "jimmy sanwo"
    "category" => "WAEC"
    "year" => "1988"
    "correct_answer" => "2.02"
    "question_id" => "3"
  ]
  1 => array:5 [▼
    "username" => "jimmy sanwo"
    "category" => "WAEC"
    "year" => "1988"
    "correct_answer" => "5.4 × 10^-2"
    "question_id" => "3"
  ]
  2 => array:5 [▼
    "username" => "jimmy sanwo"
    "category" => "WAEC"
    "year" => "1988"
    "correct_answer" => "2/3"
    "question_id" => "3"
  ]
]

jsanwo64 left a reply on Insert Array Values Into Database In Laravel

<form method="post" action="/submit_quiz" id="quiz_form" >
{{ csrf_field() }}
            <b> Questions</b>
    <div style="max-height:60%;overflow-y:auto;">

@foreach($answers as $answer)

<input type="hidden" name="name" value="{{Auth::user()->name}}">
<input type="hidden" name="category" value="{{$answer->category}}">
<input type="hidden" name="year" value="{{$answer->year}}">

<input type="hidden" name="question_id" value="{{$answer->id}}">
            <P>{{$answer->id}}.<BR>
                <select name="answer[]">
                    <option></option>
                    <option value="{{$answer->option_A}}">{{$answer->option_A}}</option>
                    <option value="{{$answer->option_B}}">{{$answer->option_B}}</option>
                    <option value="{{$answer->option_C}}">{{$answer->option_C}}</option>
                    <option value="{{$answer->option_D}}">{{$answer->option_D}}</option>
                    <option value="{{$answer->option_E}}">{{$answer->option_E}}</option>
                </select>
</p>
<br>

@endforeach
<button class="btn btn-danger"  onClick="javascript:cancelmove();" style="margin-top:2px;" >Submit Quiz</button>


    
<br>
<br>
<br>

</form>






public function submit_quiz(Request $request)
{


    $answer = new Answers;

    $data = $request->all();
     for ($i = 1; $i < count($request->answer); $i++) {
        $answers[] = [
            'username' => Auth::user()->name,
            'category' => $request->category,
            'year' => $request->year,
            'correct_answer' => $request->answer[$i],
            'question_id' => $request->question_id,
        ];
    }
    dd($answers);

jsanwo64 started a new conversation Insert Array Values Into Database In Laravel

I have 3 different questions those are coming from database randomly. Now I want to insert the question_id, user_name and user_answer into 'answers' table. Data was inserted, but here is some on for two questions not three

10 Nov
2 years ago

jsanwo64 left a reply on Laravel Not Accecesable Using Localhost

try downloading the zip file then try to change the permissions then try composer install after which you will do php artisan serve

jsanwo64 started a new conversation Using The "where" Clause Twice In A Code

Using the where Clause twice in a code. i don't know if it seems right or not

Example is this correct: $use = DB::table('added_menu')->where('name', $name)->where('menu_name', 'Main Course')->get();

03 Sep
3 years ago

jsanwo64 left a reply on Upload Image With Laravel 5.1

public function update_avatar(Request $request) { if($request->hasFile('avatar')){ $avatar = $request->file('avatar'); $filename = time() . '.' . $avatar->getClientOriginalExtension(); Image::make($avatar)->resize(300, 300)->save( public_path('uploads/avatars/' . $filename)); $user = Auth::user(); $user->avatar = $filename; $user->save(); } return view('home'); }

jsanwo64 left a reply on Multiple Upload With Laravel

Why not try what devdojo did here https://youtu.be/--9I5wqXgUM