jeudi 3 décembre 2020

How do I dynamically chain a function in Larevel?

In my Laravel Scheduler

protected function schedule(Schedule $schedule)
{

    if(env('APP_DEBUG') == true){
        $cronInterval = 'everyMinute()';
    } else {
        $cronInterval = 'daily()';
    }


    $schedule->command('inspire')
            ->$cronInterval
            ->emailOutputTo(env('MAIL_TO')); // tried 

How do I dynamically chain a function in Larevel ?

enter image description here



via Chebli Mohamed

Exporting Laravel Model to Excel but with modification of created_at column to only date not datetime

i tried to modify a collection before returning it to be exported with maatwebsite Excel. The column i tried to modify is the created_date column (the default created_date of laravel) so that when exported to excel, i only get the date not datetime.

i tried:

namespace App\Exports;

use App\Invoice;
use Maatwebsite\Excel\Concerns\FromCollection;

class InvoicesExport implements FromCollection
{
    public function collection()
    {
        $temp = Invoice::all();
        $len = count($temp);
        for($i=0;$i<$len;$i+=1){
            $temp[$i]->created_at = $temp[$i]->created_at->format('m/d/Y')
        }
        return $temp;
    }
}

in the controller:

public function export() 
{
    return Excel::download(new InvoicesExport, 'invoices.xlsx');
}

but, when exported, the result in the excel file is, for example: '07/26/2016T00:00:00.000000Z'

i noticed that the time become zero, and when i tried:

$temp[$i]->created_at = "some random string"

the laravel in webpage return error said that "some random string" cannot be parsed to datetime by Carbon Class constructor.

how can i make the exporting does not construct datetime with the string i give in the 'created_at' column, but just return the plain string instead? if let's say, i can't modify the database so i can't create extra column and extra column for this simple thing is too much, i think.



via Chebli Mohamed

Exporting Laravel Model to Excel but with modification of created_at column to only date not datetime

i tried to modify a collection before returning it to be exported with maatwebsite Excel. The column i tried to modify is the created_date column (the default created_date of laravel) so that when exported to excel, i only get the date not datetime.

i tried:

namespace App\Exports;

use App\Invoice;
use Maatwebsite\Excel\Concerns\FromCollection;

class InvoicesExport implements FromCollection
{
    public function collection()
    {
        $temp = Invoice::all();
        $len = count($temp);
        for($i=0;$i<$len;$i+=1){
            $temp[$i]->created_at = $temp[$i]->created_at->format('m/d/Y')
        }
        return $temp;
    }
}

in the controller:

public function export() 
{
    return Excel::download(new InvoicesExport, 'invoices.xlsx');
}

but, when exported, the result in the excel file is, for example: '07/26/2016T00:00:00.000000Z'

i noticed that the time become zero, and when i tried:

$temp[$i]->created_at = "some random string"

the laravel in webpage return error said that "some random string" cannot be parsed to datetime by Carbon Class constructor.

how can i make the exporting does not construct datetime with the string i give in the 'created_at' column, but just return the plain string instead? if let's say, i can't modify the database so i can't create extra column and extra column for this simple thing is too much, i think.



via Chebli Mohamed

Laravel session is lost in Android Chrome Incognito mode post sign-in

Recently we noticed a login issue in Android Mobile Incognito mode wherein post user sign in and on page reload, user signed state is not retained. We debugged this further and noticed that post login, request token and session token doesn't match i.e. session token gets reset. We suspect this is causing the sign in issue but we are not able to figure out what could be causing session token to be reset.

Any pointers on this issue or suggestions to debug would be helpful.



via Chebli Mohamed

mercredi 2 décembre 2020

How to change the collection on the basis of array in column value

I want to change the laravel collection because I want to pass this collection to generate report. How to change collection on the basis of the value in the column.

Previous:

Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[id] => 23
[form_type] => radio
[details] => [{"id":55 title:"AA" name:"BB"}, {"id":56 title:"CC" name:"DD"}]
)
[1] => stdClass Object
(
[id] => 24
[form_type] => checkbox
[details] => [{"id":57 title:"PP" name:"QQ"}, {"id":58 title:"RR" name:"SS"}]
)
)
)

--details column has array of objects, I want it as below format:

Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[id] => 23
[form_type] => radio
[title] => "AA"
[name] =>  "BB"     
)
[1] => stdClass Object
(
[id] => 23
[form_type] => radio
[title] => "CC"
[name] =>  "DD"     
)        
[2] => stdClass Object
(
[id] => 24
[form_type] => checkbox
[title] => "PP"
[name] =>  "QQ"
)
[4] => stdClass Object
(
[id] => 24
[form_type] => checkbox
[title] => "RR"
[name] =>  "SS"
)
)
)


via Chebli Mohamed

How to do the breadcrumbs with passing id using davejamesmiller in Laravel

I using davejamesmiller/laravel-breadcrumbs package for the breadcrumbs I facing one issue that was I have one Sub-Category it's assigned to two different Top-Category It's like this.

Top Category = Apparel(1) Hoodies(2)

Sub Category = Hoodies(1) Hoodies(1)

If I click the Hoodies on Apparel Breadcrumb have to show like this Home / Apparel / Hoodies. In URL I just passing the Sub Category ID only. How can I identify that clicked subcategory belongs to which top category. Please help me to fix this issue. I attached the breadcrumbs.php file code.

<?php

// Home
use App\top_level_category;

Breadcrumbs::for('Home', function ($trail) {
    $trail->push('Home', route('Home'));
});

// Top Category
Breadcrumbs::for('Category', function ($trail, $id) {
    $topCate = top_level_category::where('tolc_seo_title',$id)->first();
    $trail->parent('Home');
    $trail->push($topCate->tolc_name, route('Category', $topCate));
});

// Sub Category
Breadcrumbs::for('Sub_Category', function ($trail, $id) {
    $subCate = sub_category_one::where('suco_seo_title',$id)->first();
    $trail->parent('Home');
    //Here Have to come top category which I click
    $trail->push($subCate->suco_name, route('Sub_Category', $subCate));
});

<div class="breadcrumb">
    <ul>
       <li>
          {!! Breadcrumbs::render() !!}
       </li>
    </ul>
</div>


via Chebli Mohamed

export data in excel by view using find in set

i have three table i wanted to know how to export data using find_in_set from my database table also i wanted to know how can i export data from other tables in same excel sheet by using seconday id

here is by controller

<?php
namespace App\Http\Controllers;
use DB;
use Excel;
use App\ProductsExport;
use Illuminate\Http\Request;
class ImportExportController extends Controller
 {
   public function importExportView()
   {
     return view('dashboard.excel.export_excel');
   }
   public function export(Request $request)
   {
    return Excel::download(new ProductsExport($request->primaryCategory), 'products.xlsx');
   } 

}

and here is my model for exporting data

<?php
 namespace App;
 use App\ProductAdd;
 use Maatwebsite\Excel\Concerns\FromQuery;
 use Maatwebsite\Excel\Concerns\ShouldAutoSize;
 use Illuminate\Contracts\View\View;
 use Maatwebsite\Excel\Concerns\FromView;
 use Maatwebsite\Excel\Concerns\Exportable;
 use DB;
 class ProductsExport implements ShouldAutoSize, FromView
  {
    use Exportable;
    public $catId;
    public function __construct($catId)
    {
      $this->catId = $catId;
    }
   public function view(): View
    {
       return view('dashboard.excel.export', [
      'users' => ProductAdd::whereRaw("FIND_IN_SET(?, primaryCategory) > 0", explode(',', $this->catId))->get();
    ]);
} 

on view page ist givind blank. also please help me for importing data on three tables using same process



via Chebli Mohamed