Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

rubol

Experience

8,500

2 Best Reply Awards

  • Member Since 1 Year Ago
  • 69 Lessons Completed
  • 0 Favorites

13th October, 2017

rubol left a reply on Show Message In Alert Box Wih Ajax And Json Laravel • 2 months ago

Removed action and method attribute from the form. It is working fine.

rubol started a new conversation Show Message In Alert Box Wih Ajax And Json Laravel • 2 months ago

I have the following ajax code:

    $(function() {
             // Get the form.
         var form = $('#ajax-inquire');

          // Get the messages div.
        var formMessages = $('#form-messages');


        // Set up an event listener for the contact form.
        $(form).submit(function(event) {
        // Stop the browser from submitting the form.
        event.preventDefault();

        // Serialize the form data.
        var formData = $(form).serialize();


            // Submit the form using AJAX.
    $.ajax({
        type: 'POST',
        url: $(form).attr('action'),
        data: formData
    })
    .done(function(response) {
     // Make sure that the formMessages div has the 'success' class.
     formMessages.removeClass('alert-danger');
        formMessages.addClass('alert-success');

        // Set the message text.
        $(formMessages).text(response);

        // Clear the form.
         $('#fullName').val('');
        $('#email').val('');
        $('#telephone').val('');
        $('#message').val('');
        formMessages.show();
    })
.   fail(function(data) {
        // Make sure that the formMessages div has the 'error' class.
     formMessages.removeClass('alert-success');
         formMessages.addClass('alert-danger');

     // Set the message text.
        if (data.responseText !== '') {
            $(formMessages).text(data.responseText);
        } else {
            $(formMessages).text('Oops! An error occured and your message could not be sent.');
     }
        formMessages.show();
            });

        });

    });

And my code in controller:

    public function postInquire(Request $request)
{
        $data = array(
         'tripName' => $request->tripName,
         'fullName' => $request->fullName,
          'email' => $request->email,
          'telephone' => $request->telephone,
         'bodyMessage' => $request->message
 );

     Mail::to('[email protected]')->send(new TourInquire($data));
        return response()
         ->json(['code'=>200,'success' => 'Your inquire is successfully sent.']);
 }

And my route for posting my ajax form is:

Route::post('/inquire', '[email protected]')->name('postInquire');

With the above codes I'm able to send mail via ajax request. I'm trying to show json response message in alert box in my view. But I'm unable to do so as json response message is show in white page with url of my post route for form.

HTML code in view:

    <div class="modal-body">
            <div id="form-messages" class="alert success" role="alert" style="display: none;"></div>
            <div class="preview-wrap">

                <img src="{{asset($tour->featuredImage->path)}}" class="preview-img thumbnail" alt="{{$tour->featuredImage->name}}">
                <div class="form-wrap">
                    <form action="{{route('postInquire')}}" id="'#ajax-inquire" method="POST">
                        {{csrf_field()}}
                        <div class="form-group">
                            <input type="hidden" name="tripName" id="tripName" value="{{$tour->title}}">
                            <label>Name</label>
                            <input type="text" class="form-control" placeholder="Enter Your Full Name" name="fullName" id="fullName" required>
                        </div>
                        <div class="form-group">
                            <label>Email</label>
                            <input type="email" class="form-control" placeholder="Email Address" name="email" id="email" required>
                        </div>
                        <div class="form-group">
                            <label for="telephone">Phone</label>
                            <input type="tel" class="form-control" placeholder="Phone Number" name="telephone" id="telephone" required>
                        </div>
                        <div class="form-group">
                            <label for="message">Message</label>
                            <div class="row">
                                <textarea name="message" id="message" cols="30" rows="5" class="form-control"></textarea>
                            </div>
                        </div>
                        <button class="btn btn-primary hvr-sweep-to-right">Send Message</button>
                    </form>
                </div>
            </div>
        </div>

11th October, 2017

rubol left a reply on Use Scope Function • 2 months ago

Removed orderBy('start', 'asc') from Tour.phperror gone.

rubol started a new conversation Use Scope Function • 2 months ago

I have two models that are in one to many relationship

Tour.php

`class Tour extends Model{ protected $table = 'tours';

public function datePrice() { return $this->hasMany('App\DatePrice', 'tour_id')->orderBy('start', 'asc'); } }and`` DatePrice.php

`class DatePrice extends Model { public $timestamps = false; protected $table = 'dateprice'; protected $fillable = ['tour_id','start_day','start_month','start_year','end_day','end_month','end_year','price']; public function tour() { return $this->belongsTo('App\Tour', 'tour_id'); }

public function scopeFixedDates($query, $id, $date)
{
    return $query->where('tour_id', '=' , $id )->where('start_year', '=' , $date)->get();
}

}`

I'm trying to get dates of a tour according to the tour id and year passed as parameter to the model function in to my view .

My code in controller:

` public function tourDetail($category,$slug) { $tour = Tour::whereHas('category', function($r) use($category) { $r->where('tcategories.name','=', $category); }) ->where('slug','=', $slug) ->first();

    return view('public.tour.tour-detail')
    ->withTour($tour)
    ->with(['dates' => $tour->datePrice()->FixedDates($tour->id,date('Y'))->get()]);
}

`

But I'm getting this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'start' in 'order clause' (SQL: select * fromdatepricewheredateprice.tour_id= 1 anddateprice.tour_idis not null andtour_id= 1 andstart_year= 2017 order bystartasc)

While my table structure for dateprice is id | tour_id | start_day | start_month | start_year | end_day | end_month | end_year

Can anyone help me on this ?

10th July, 2017

rubol started a new conversation Cannot Use Object Of Type StdClass As Array • 5 months ago

I'm using Instagram Package for laravel. The below method returns results in array form:

public static function instaPosts() { $instagram = new Instagram(); $items = $instagram->get('lauraiz');

return $items; }

array:20 [▼
0 => {#430 ▼
    +"id": "1554751710723134586_11443906"
    +"code": "BWTlnGHlVR6"
    +"user": {#433 ▶}
    +"images": {#427 ▶}
    +"created_time": "1499560868"
    +"caption": {#432 ▶}
    +"likes": {#440 ▶}
    +"comments": {#449 ▶}
    +"can_view_comments": true
+"can_delete_comments": false
    +"type": "carousel"
+"link": "https://www.instagram.com/p/BWTlnGHlVR6/"
    +"location": null
    +"alt_media_url": null
    +"carousel_media": array:4 [▶]
}
1 => {#482 ▶}
 2 => {#504 ▶}
3 => {#524 ▶}
  4 => {#546 ▶}
  5 => {#569 ▶}
  6 => {#591 ▶}
  7 => {#613 ▶}
  8 => {#633 ▶}
  9 => {#656 ▶}
  10 => {#679 ▶}
  11 => {#701 ▶}
  12 => {#724 ▶}
  13 => {#744 ▶}
  14 => {#798 ▶}
  15 => {#822 ▶}
  16 => {#844 ▶}
  17 => {#866 ▶}
  18 => {#888 ▶}
  19 => {#910 ▶}
]

I want to get url of thumbnail from images key of every array index. I've tried the following code:

array:20 [▼
0 => {#430 ▼
    +"id": "1554751710723134586_11443906"
    +"code": "BWTlnGHlVR6"
    +"user": {#433 ▶}
    +"images": {#427 ▼
      +"thumbnail": {#428 ▼
        +"width": 150
        +"height": 150
        +"url": "https://instagram.fktm3-1.fna.fbcdn.net/t51.2885-      15/s150x150/e35/19954999_1933558183580105_9022206750941511680_n.jpg"
  }
         +"low_resolution": {#439 ▶}
    +"standard_resolution": {#429 ▶}
    }
    +"created_time": "1499560868"
    +"caption": {#432 ▶}
    +"likes": {#440 ▶}
    +"comments": {#449 ▶}
    +"can_view_comments": true
    +"can_delete_comments": false
    +"type": "carousel"
    +"link": "https://www.instagram.com/p/BWTlnGHlVR6/"
    +"location": null
    +"alt_media_url": null
    +"carousel_media": array:4 [▶]
  }

And my code in view:

                        @foreach($items as $item)
                        @foreach($item['images'] as $k)                             
                        <li><img src="{{$k['thumbnail']['url']}}" alt="instagram"></li>
                        @endforeach
                        @endforeach 

But I'm getting error of:

Cannot use object of type stdClass as array

21st June, 2017

rubol left a reply on Search With Date Range In Laravel • 5 months ago

The date format of start and end is in yyyy-mm-dd:

    $(function(){$("#start").datepicker({
            autoclose:!0,
            format:"yyyy-mm-dd",
            startDate:new Date
        }),
        $("#end")
    .   datepicker({
            autoclose:!0,
            format:"yyyy-mm-dd",
            startDate:new Date
        })
    }); 

In database dates are saved in same format i.e 2017-03-21

rubol started a new conversation Search With Date Range In Laravel • 5 months ago

I have a db table dateprices

id|tour_id|start|end|price

I want to get all the price of the tour starting between the dates i.e. 2017-06-21 and 2017-06-22

I have written following query but it is giving me all rows of the table:

    public function datePrice(Request $request){
    $start = $request->start;
    $end = $request->end;

    $dates = DatePrice::where('tour_id','=',$request->product_id)
    ->whereBetween('start', array($request->start, $request->end))
    ->get();

    return response()->json($dates);
    }

rubol left a reply on Route Not Going Where It's Supposed To • 5 months ago

Route::get('/product-category/{category}/{slug}', [
    'uses' => '[email protected]',
    'as' => 'product.item',
])

->where('category', '[A-Za-z\d-_]+') ->where('slug', '[A-Za-z\d-_]+');

20th June, 2017

rubol left a reply on Sometimes Routes Brake, Undefined? • 5 months ago

You've used a hell lot pf prefix I should say.

    Route::group(['prefix' => '/customers'], function () {
        Route::resource('/newcustomer','CustomerController',['only'=>['index','create','store'] ]);
      Route::resource('/customer_profile','CustomerController',['only'=>['show','edit','update'] ]);        
    });

Try this and let me know if this works or not.

19th June, 2017

rubol left a reply on Route Not Going Where It's Supposed To • 5 months ago

Try this regex this should do the job: Route::get('/{category}/{slug}','[email protected]') ->where('category', '[A-Za-z\d-_]+') ->where('slug', '[A-Za-z\d-_]+') ->name('product.item');

Nothing fancy here, new method of naming route with laravel 5.4 and validation of parameter with regex.

rubol left a reply on Route Not Going Where It's Supposed To • 5 months ago

I highly recommend you to use prefix for your admin section routes.

Route::prefix('admin')->group(function() {
    Route::resource('menus', 'MenusController');
    });

Now you can write your routes as regular route menus.create,... etc. The route you place inside the group will now come with prefix (admin). i.e. http://localhost:8000/admin/menus/create

And place all your public out of the group function.

16th June, 2017

rubol left a reply on Update Data Into Table From Dynamically Created Input Field • 5 months ago

@bunnypro the snippet you suggested is also doing the same as mine. Creating new rows instead of updating it. I think it is impossible to achieve the way I want. Can you guys suggest other alternative ways ?

rubol left a reply on Update Data Into Table From Dynamically Created Input Field • 5 months ago

FYI I'm using same form to create records for tours table and itinerary table.

rubol left a reply on Update Data Into Table From Dynamically Created Input Field • 5 months ago

This is my code in tour.edit view:

          <div class="col-md-12">
                <div class="row" v-for="row in rows">
                    <div class="col-md-2">
                     {{ Form::label('day', "Day:", ['class' => 'form-label-margin', ])}}
                     <input type="text" name="day[]"  v-model="row.day" class="form-control">        
                </div>
                <div class="col-md-8">
                    {{ Form::label('itinerary', " Tour itinerary:", ['class' => 'form-label-margin'])}}
                    <textarea name="itinerary[]" v-model="row.plan" class="form-control" id="itinerary"></textarea>
                </div> 
                <div class="col-md-2">
                    <button class="btn btn-danger"  @click.prevent="deleteOption(row)"><i class="fa fa-trash"></i></button>
                </div>              
            </div>
        <div class="row">
          <button class="btn btn-primary add" @click.prevent="addNewOption" ><i class="fa fa-plus"></i> Add Field</button>

        </div>
      </div>

rubol left a reply on How To Make A Url Like Domain.com/?&search=something Trigger An Eloquent Query? • 5 months ago

It's simple and easy. First you need to make function(method) that handles the search query and define route. Below is the code snippet from my project for search:

    public function search(Request $request)
        {
            $days = $request->days;
            $days_explode = explode('|', $days);

            $query = Tour::query();

            if (!empty($request->country)) {
                $query = $query->whereHas('country', function($r)       use($request) {
                $r->where('countries.name', $request->country);
                });
        }

        if (!empty($request->category)) {
            $query = $query->whereHas('category', function($s) use($request) {
                $s->where('categories.name', $request->category);
                });
        }

        if (!empty($request->days)) {
                $query = $query->whereBetween('days', [$days_explode[0],        $days_explode[1]]);
        }            

        $query = $query->paginate(8);        
            return view('public.tour.search')->withResults($query);
        }

And route is: Route::get('/trip/search','[email protected]') ->name('search');

In my case I had used search form with multiple parameter(3 parameters). Less the no. of parameters, easy it will be.

rubol left a reply on Sometimes Routes Brake, Undefined? • 5 months ago

@Snapey can you help me with my [issue] (https://laracasts.com/discuss/channels/eloquent/update-data-into-table-from-dynamically-created-input-field) ? I found you answering same kind of issue.

rubol left a reply on Two Table Join & Sum • 5 months ago

Have you setup relationship between models ??

rubol left a reply on Sometimes Routes Brake, Undefined? • 5 months ago

Can you share your route codes ? And the code from the view where you are using foreach loop.

rubol left a reply on ClaClass 'Html' Not Found (View: C:\laragon\www\Laragon\resources\views\layouts\master.blade.php) • 5 months ago

For v.5.3 composer require "laravelcollective/html":"^5.3.0"

For v.5.2 composer require "laravelcollective/html":"^5.2.0"

For v.5.1 add require parameter of composer.json file "laravelcollective/html": "5.1.*"

For v.5.0 add require parameter of composer.json file "laravelcollective/html": "~5.0"

rubol left a reply on ClaClass 'Html' Not Found (View: C:\laragon\www\Laragon\resources\views\layouts\master.blade.php) • 5 months ago

Try older version of laravel collective instead.

rubol left a reply on ClaClass 'Html' Not Found (View: C:\laragon\www\Laragon\resources\views\layouts\master.blade.php) • 5 months ago

If you haven't installed installed laravelcollective run

composer require "laravelcollective/html":"^5.4.0"

in terminal.

rubol left a reply on ClaClass 'Html' Not Found (View: C:\laragon\www\Laragon\resources\views\layouts\master.blade.php) • 5 months ago

First check your composer.json file whether you have installed laravelcollective/html package or not.

Check you config/app.php: file for 'providers' => [ // ... Collective\Html\HtmlServiceProvider::class, // ... ], and

  'aliases' => [
    // ...
     'Form' => Collective\Html\FormFacade::class,
     'Html' => Collective\Html\HtmlFacade::class,
 // ...
 ],

Try also running composer update

rubol left a reply on Inserting And Updating Data From Dynamic Form Properly • 5 months ago

@ ashisharyal how did you update the records ?

rubol started a new conversation Update Data Into Table From Dynamically Created Input Field • 5 months ago

I have 2 models Tour.php

public function tour() { return $this->belongsTo('App\Tour', 'tour_id'); } and

Itinerary.php

public function Itinerary() { return $this->hasMany('App\Itinerary', 'tour_id'); }

tours table:

id|title|content

itineraries table:

id|tour_id|day|plan

I used following code to insert into itineraries:

` $itineraries = [];

$day        = $request->input('day');
$plan  = $request->input('itinerary');

foreach ($day as $i => $name) {
    $itineraries[] = new Itinerary([
        'tour_id' => $tour->id,
        'plan' => $plan[$i],
        'day' => $day[$i],
        ]);
}
$tour->itinerary()->saveMany($itineraries);`

And tried the following code to update those inserted records:

` $count = count($request->input('day')); $temp_day = $request->input('day'); $temp_itinerary = $request->input('itinerary'); $tour_id = $tour->id;

    // dd($iterneary);
    $itinerary = Itinerary::where('tour_id', $tour_id);
    for($i = 0; $i <$count; ++$i) 
    {
        $itinerary->updateOrCreate([
            'tour_id' => $tour_id,
            'plan' => $temp_itinerary[$i],
            'day' => $temp_day[$i],
            ]);
    }`

But it is adding additional rows instead of updating the rows. example: First inserted rows: id|tour_id|day|plan 1| 1 | 1 | test

After update: id|tour_id|day|plan 1| 1 | 1 | test 1| 1 | 1 | test test 1| 1 | 2 | test test

How can I update the rows without creating the new one ?

17th November, 2016

rubol left a reply on Laravel Query Builder (where) With Pivot Table • 1 year ago

@lrs64 I know that. My question is to fetch data using query builder.

rubol started a new conversation Laravel Query Builder (where) With Pivot Table • 1 year ago

I have two tables with a pivot table

Table 1: tours | id | name | country_id |featured Table 2: countries | id | name | Piviot table: country_tour | id | country_id | tour_id|

I want to to find the tour that has featured column of tours table set to 1 and country_id of country_tour table set to 1.

How can i accomplish this with query builder ?I have been googling for this whole day, but couldn't find solution.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.