rubol

Experience

8,280

2 Best Reply Awards

  • Member Since 9 Months Ago
  • 68 Lessons Completed
  • 0 Favorites

10th July, 2017

rubol started a new conversation Cannot Use Object Of Type StdClass As Array • 1 month 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 • 1 month 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 • 1 month 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 • 1 month 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? • 2 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 • 2 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 • 2 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 • 2 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 • 2 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 • 2 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? • 2 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? • 2 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 • 2 months ago

Have you setup relationship between models ??

rubol left a reply on Sometimes Routes Brake, Undefined? • 2 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) • 2 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) • 2 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) • 2 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) • 2 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 • 2 months ago

@ ashisharyal how did you update the records ?

rubol started a new conversation Update Data Into Table From Dynamically Created Input Field • 2 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 • 9 months 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 • 9 months 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.