Why changes of element array has not effect?

I have a function that has input array of lines. Each line has columns array. Iteration whole lines and columns a I try to change column in loop:

<?php
function parseColumns($lines, $regexFunctions)
{

    $parsedColumns = [];

    foreach ($lines as $line)
    {
        $lineindex = $line["indexLine"];
        $columns = $line["columns"];
        $group = $line["group"];
        $usedRegexFunctions = [];

        foreach ($columns as $columnindex => $column)
        {
            $value = trim($column["value"]);
            $value = replaceTab($value);
            $value = replaceSpecialSymbols($value);
            $col = array(
                "columnindex" => $columnindex,
                "lineindex" => $lineindex,
                "group" => $group,
                "value" => $value,
                "valid" => NULL,
                "columnname" => NULL,
                "columnid" => NULL
            );

            foreach ($regexFunctions as $validatorId => $validator)
            {
                $validatorName = $validator["name"];
                $validator = $validator["validator"];

                if (key_exists($validatorName, $usedRegexFunctions)) continue;

                $match = $validator($value);
                if ($match)
                {
                    $usedRegexFunctions[$validatorName] = $validatorName;
                    $col["columnname"] = $validatorName;
                    $col["columnid"] = $validatorId;
                    $column["columnname"] = $validatorName;
                    $column["columnid"] = $validatorId;
                    break;
                }
            }

            $parsedColumns[] = $col;
        }

        $_lines[] = $parsedColumns;
    }

    return $_lines; //$parsedColumns;
    
}

Problem is on the line, where I detect type of column and try to apply this to current column:

$column["columnname"] = $validatorName;
$column["columnid"] = $validatorId;

After all I dump variable $_lines and can not see changes.
I tried to pass $lines as link &$lines, no effect.

Unable to search data in a mongodb database using laravel

I am trying to write a query to search the mongodb database for a specific query and return the associated information here is what I have done so far:
In Post:

<?php 
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use JenssegersMongodbEloquentModel;
class Post extends Model
{

use HasFactory;
protected $connection = 'mongodb';
protected $collection = 'post';
protected $fillable = [
'STATUS',
'DDC_CODE',

'TRADE_NAME',

'SCIENTIFIC_CODE',

'SCIENTIFIC_NAME',

'INGREDIENT_STRENGTH',

'DOSAGE_FORM_PACKAGE',

'ROUTE_OF_ADMIN',
'PACKAGE_PRICE',

'GRANULAR_UNIT',

'MANUFACTURER',

'REGISTERED_OWNER',

'UPDATED_DATE',

'SOURCE'
];}

In PostController:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppModelsPost;

class PostController extends Controller
{

public function home() {
    $posts = Post::paginate(4);

    return view('home', compact('posts'));
}
public function search(Request $request){
    
    if(isset($_GET['query'])){
        $search_text=$_GET['query'];
        $searchs=Post::whereRaw(array('$text'=>array('$search'=> $search_text)))->get();;
        return view('search',['searchs'=>$searchs]);
    }
    else{
        return view('search');
    }
 }
}

And the search.blade.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Laravel search</title>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-6" style="margin-top:40px">
            <h4>Search Everything</h4><hr>
            <form action="{{ route('web.search')}}" method="GET">
                <div class="form-group">
                    <label for="">Enter keyword</label>
                    <input type="text" class="form-control" name="query" placeholder="Search here...">
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary">Search</button>
                </div>
            </form>
            <br>
            <br>
            <hr>
            <br>
            <table border = "1">
            <tr>
            <td>STATUS</td>
            <td>DDC_CODE</td>
            <td>TRADE_NAME</td>
            <td>SCIENTIFIC_CODE</td>
            <td>SCIENTIFIC_NAME</td>
            <td>SCIENTIFIC_CODE</td>
            <td>INGREDIENT_STRENGTH</td>
            <td>DOSAGE_FORM_PACKAGE</td>
            <td>ROUTE_OF_ADMIN</td>
            <td>PACKAGE_PRICE</td>
            <td>GRANULAR_UNIT</td>
            <td>MANUFACTURER</td>
            <td>UPDATED_DATE</td>
            <td>SOURCE</td>
            </tr>
            @foreach ($searchs as $search)
            <tr>

            <td>{{ $search['STATUS'] }}</td>
            <td>{{ $search['DDC_CODE'] }}</td>
            <td>{{ $search['TRADE_NAME'] }}</td>
            <td>{{ $search['SCIENTIFIC_CODE'] }}</td>
            <td>{{ $search['SCIENTIFIC_NAME'] }}</td>
            <td>{{ $search['INGREDIENT_STRENGTH'] }}</td>
            <td>{{ $search['DOSAGE_FORM_PACKAGE'] }}</td>
            <td>{{ $search['ROUTE_OF_ADMIN'] }}</td>
            <td>{{ $search['PACKAGE_PRICE'] }}</td>
            <td>{{ $search['GRANULAR_UNIT'] }}</td>
            <td>{{ $search['MANUFACTURER'] }}</td>
            <td>{{ $search['REGISTERED_OWNER'] }}</td>
            <td>{{ $search['UPDATED_DATE'] }}</td>
            <td>{{ $search['SOURCE'] }}</td>
            </tr>
            @endforeach
            </table>
</body>
</html>

Also the route handler web.php:

<?php

use IlluminateSupportFacadesRoute;
use AppHttpControllersPostController;

Route::get('/', function () {
     return view('welcome');
});
Route::get('view','AppHttpControllersPostController@home');
Route::get('/search',[PostController::class,'search'])- 
>name('web.search');

When I run the code for some reason it gives me a ErrorException Undefined variable: searchs in the search.blade.php and marks the first line of the loop. Also there is no problems with the connection itself as the home method in the postController runs flawlessly. I believe there is one of two possibilities the query in my post controller is wrong and is therefore causing the error or something is wrong in the blade file not sure which. Any and all help is appreciated.

How validate an array? (Laravel)

How can I validate this array in laravel validation:

"price" => array:1 [▼
           0 => array:1 [▼
                "price.value" => 50
]

I tried to use this, but it does’t working:

'price.0.price.value' => ['required']

How can I solve?
I want to note that: I have no choice to change the name “price.value”.

Redirect with data back to where the form was completed laravel

I have a form from which the controller gets the data requested from the db. I want to then redirect to the same page as the form but with the data i got from the db. I am using laravel 5.5

This is my controller for the store:

    public function listsStore(Request $request) {
        $data = $request->all();
        $user = $request->user;
        $day = date('Y-m-d', strtotime($request->day));
        $from =  date('Y-m-d', strtotime($request->from));
        $to = date('Y-m-d', strtotime($request->to));
        $radio = $data['radio-btn'];

        // dd($user, $from, $to);
        // dd($radio);

        if($radio === 'tasks') {
            if($request->day) {
                $tasks = Task::where('user_id', $user)
                        ->whereDate('start', $day)
                        ->orderBy('start','DESC')
                        ->get();
                // dd($tasks);
                return redirect()->back()->with('tasks', $tasks);
            }else{ // gets for the range of dates requested
                $tasks = Task::where('user_id', $user)
                        ->whereBetween('start',[$from, $to])
                        ->orderBy('start','DESC')
                        ->get()
                        ->groupBy(function($date) {
                        return Carbon::parse($date->start)->format('Y-m-d'); 
                        });
                // dd($tasks);
                return redirect()->back()->with('tasks', $tasks);
            } 
        }elseif($radio === 'timecards'){ //IF REQUEST IS TIMECARDS
            if($request->day) { //gets for the day requested
                $timecards = Timecard::where('user_id',$user)
                            ->whereDate('checkin', $day)
                            ->orderBy('checkin','DESC')
                            ->get();
                // dd($timecards);
                return redirect()->back()->with('timecards', $timecards);
            } else{ // gets for the range of dates requested
                $timecards = Timecard::where('user_id', $user)
                            ->whereBetween('checkin',[$from, $to])
                            ->orderBy('checkin','DESC')
                            ->get()
                            ->groupBy(function($date) {
                                return Carbon::parse($date->checkin)->format('Y-m-d'); 
                            });
                // dd($timecards);
                return redirect()->back()->with('timecards', $timecards);
            }
        }
        // return redirect('backend.list');
    }

controller for the page:

    public function lists() {
        $users = User::all();
        return view( 'backend.list', compact('users'));
    }

and in the view i tried this way:

    @if(session()->has('timecards'))
        @foreach($timecards as $timecard)
            <div>{{$timecard->checkin}}</div>
        @endforeach
    @endif

Thank you

What’s wrong with my MYSQL Code query in php file?

I have two tables in mysql database

one table named is place:

place_id place active shortform country type
1 Uttar Pradesh 1 UP India State
2 Delhi 1 DELHI India Union territory
3 Punjab 1 PUN India State
4 Karnataka 1 KAR India State
5 Kerala 1 KER India State
6 Lucknow 1 LKO India Capital
7 Chandigarh 1 CHA India Capital
8 Bengaluru 1 BEN India Capital
9 Thiruvanthapuram 1 THI India Capital
10 Saharanpur 1 SAH India District
11 Meerut 1 MEE India District
12 Gorakhpur 1 GOR India District

and other named as place_capital

id_place_place place_parent place_child
1 1 6
2 3 7
3 4 8
4 5 9
5 1 10
6 1 11
7 1 12

I run this query

select *, group_concat(place_capital.place_child) AS Group from place
left join place_capital on place.place_id = place_place.place_parent
where place.place_id = place_place.place_parent and active = :active AND type = :type
group by place ORDER BY place

and it give the following result

place_id place active shortform country type id_place_place place_parent place_child Group
1 Uttar Pradesh 1 UP India State 1 1 6 6,10,11,12
3 Punjab 1 PUN India State 2 3 7 NULL
4 Karnataka 1 KAR India State 3 4 8 NULL
5 Kerala 1 KER India State 4 5 9 NULL

What query I used in php file to give the following result that include Delhi also.
The place table have some relationship with place_place table. with my above sql query that not give the Delhi in the result. So, what is the thing I missed in the php file to get the below result.

place_id place active shortform country type id_place_place place_parent place_child Group
1 Uttar Pradesh 1 UP India State 1 1 6 6,10,11,12
2 Delhi 1 DELHI India Union Territory NULL NULL NULL NULL
3 Punjab 1 PUN India State 2 3 7 NULL
4 Karnataka 1 KAR India State 3 4 8 NULL
5 Kerala 1 KER India State 4 5 9 NULL

and here is the code in the php file:-

public function __construct(Querier $db, $type = "", $active = 1) {
$this->db = $db;
$this->type = $type;
$this->active = $active;

$connection = $this->db->getConnection();

if ($this->type != "") {
    $statement = $connection->prepare("select *, group_concat(place_capital.place_child) AS Group from place
                                    left join place_capital on place.place_id = place_place.place_parent
                                    where place.place_id = place_place.place_parent and active = :active AND type = :type
                                    group by place ORDER BY place ");
    $statement->bindParam(":type", $this->type);
} else {
    $statement = $connection->prepare("SELECT * FROM place WHERE active = :active ORDER BY place ");
}

$statement->bindParam(":active", $this->active);
$statement->execute();
$this->_guide_list = $statement->fetchAll();

}

How to deploy Django Based Server and Laravel Project Simultaneously on a Single Droplet

I am new to Digital Ocean and was wondering on how to deploy Django and Laravel code side-by-side. The code works fine locally but I don’t know how to deploy the both sources over Digital Ocean droplet.

We bought cloudways server but it doesn’t offer anything other than PHP which was the limitation. So, we don’t have any experience with deployment on Digital Ocean.

Is there anyone who can help me with this?


Thank you!

PDO MySQL external connection stale after being inactive for specific amount of seconds

Software versions:

PHP 8.1.5 (cli)
mysql  Ver 8.0.29-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))

After migrating our database to the new server and new software I noticed strange behaviour which could be shown with this simplified code snippet below:

<?php
    $host = '<remote host (external IP)>';
    $db   = '<db name>';
    $user = '<user>';
    $pass = '<password>';
    $charset = 'utf8mb4';

    $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
    $options = [
        PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        PDO::ATTR_EMULATE_PREPARES   => false,
        PDO::ATTR_TIMEOUT            => 5
    ];
    try {
        //executing first statement, no problem
        echo 'CREATING PDO OBJECT'.PHP_EOL;
        $pdo = new PDO($dsn, $user, $pass, $options);

        echo 'PDO OBJECT CREATED, PREPARING STATEMENT'.PHP_EOL;
        $stmt = $pdo->prepare('SELECT *
                FROM someObject
                WHERE objectID = 1');
        echo 'STATEMENT PREPARED, EXECUTING STATEMENT'.PHP_EOL;
        $stmt->execute();
        echo 'STATEMENT EXECUTED, FETCHING RESULT: ';
        $result = $stmt->fetch();
        echo count($result).PHP_EOL;

        $sleep = 258;
        echo 'SLEEP: '.$sleep.PHP_EOL;
        sleep($sleep);
        echo 'WOKE UP'.PHP_EOL;

        //executing second statement after sleep, hangs
        echo 'PREPARING STATEMENT'.PHP_EOL;
        $stmt = $pdo->prepare('SELECT *
                FROM someObject
                WHERE objectID = 2');
        echo 'STATEMENT PREPARED, EXECUTING STATEMENT'.PHP_EOL;
        $stmt->execute(); //hangs here
        echo 'STATEMENT EXECUTED, FETCHING RESULT: ';
        $result = $stmt->fetch();
        echo count($result).PHP_EOL;

    } catch (PDOException $e) {
         throw new PDOException($e->getMessage(), (int)$e->getCode());
    }

This script output is:

CREATING PDO OBJECT
PDO OBJECT CREATED, PREPARING STATEMENT
STATEMENT PREPARED, EXECUTING STATEMENT
STATEMENT EXECUTED, FETCHING RESULT: 20
SLEEP: 258
WOKE UP
PREPARING STATEMENT

After this process becomes stale and does nothing, WOKE UP is the last sentence I see in the output until max execution time is reached – then the process is dropped by PHP. It happens always if logic reaches 258 seconds of database inactivity.

If I reduce sleep time to 257 seconds – it always works, I see a second result, and the script finishes successfully. For me, it looks like there is some parameter that blocks connection after 257 seconds of inactivity.
On the MySQL side, I see following

SHOW FULL PROCESSLIST;
+------+-----------------+---------------------+------------------+
| Id   | User   | Host   | db   | Command  | Time | State | Info |
+------+-----------------+---------------------+------------------+
| <id> | <user> | <host> | <db> | Sleep    | 1258 |       | NULL |
+------+-----------------+---------------------+------------------+

As you may see – Time is 1258 here, it never gets closed (only after it reaches MySQL wait_timeout).
MySQL timeouts below

+-----------------------------------+----------+
| Variable_name                     | Value    |
+-----------------------------------+----------+
| connect_timeout                   | 10       |
| delayed_insert_timeout            | 300      |
| have_statement_timeout            | YES      |
| innodb_flush_log_at_timeout       | 1        |
| innodb_lock_wait_timeout          | 50       |
| innodb_rollback_on_timeout        | OFF      |
| interactive_timeout               | 28800    |
| lock_wait_timeout                 | 31536000 |
| mysqlx_connect_timeout            | 30       |
| mysqlx_idle_worker_thread_timeout | 60       |
| mysqlx_interactive_timeout        | 28800    |
| mysqlx_port_open_timeout          | 0        |
| mysqlx_read_timeout               | 30       |
| mysqlx_wait_timeout               | 28800    |
| mysqlx_write_timeout              | 60       |
| net_read_timeout                  | 30       |
| net_write_timeout                 | 60       |
| replica_net_timeout               | 60       |
| rpl_stop_replica_timeout          | 31536000 |
| rpl_stop_slave_timeout            | 31536000 |
| slave_net_timeout                 | 60       |
| ssl_session_cache_timeout         | 300      |
| wait_timeout                      | 28800    |
+-----------------------------------+----------+
23 rows in set (0.00 sec)

You may say that the DB connection shouldn’t be kept open if not needed and I agree with that, it is what I did to fix this problem. However, on the previous server, I noticed nothing like that and wondering what’s happening here.
Please, don’t suggest using the persistent connection, I want to find the reason, not fix consequences.

Shopware 6 change shipping method programmatically in checkout on order submission

I have two of same shipping methods with different price matrix, depending on customer distance, one of the two shipping method should be selected. This has to be done programmatically on checkout order confirmation, I looked at the cart collector, but it’s about changing price of an item. I didn’t find anything covered in documentation regarding shipping method change.

private function getShippingMethod(string $id, Context $context): ?ShippingMethodEntity
{
    $criteria = new Criteria();
    $criteria->addFilter(new EqualsFilter("id", $id));
    $criteria->setLimit(1);
    $result = $this->shippingMethodRepository->search($criteria, $context);
    return $result->getEntities()->first();
}

public function onOrderValidation(BuildValidationEvent $event)
    {

        ....
   
        $cart = $this->cartService->getCart($this->salesChannelContext->getToken(), $this->salesChannelContext);

        $delivery = $cart->getDeliveries()->first();

        $shippingMethod = $this->getShippingMethod($this->getShippingMethodZoneXId(), $event->getContext());
        $delivery->setshippingMethod($shippingMethod);

}

In the above code I have cart object, and delivery. I get the shipping method which I need to set, but it doesn’t get updated.

Also i need to recalculate shipping price, what is the correct way to do it. any suggestion will be appreciated.

Re-index a php array on key

I have an array created in PHP which is used downstream in a Garmin connectIQ app. I have created a script which generates the below Var_export

  array (
  '2022-05-14' => 
  array (
    0 => 
    array (
      'index' => 0,
      'time' => '05:18:31',
      'timeE' => 1652501911,
      'type' => 'High',
      'height' => '7.9m',
      'diff' => '1day 15hrs',
    ),
    1 => 
    array (
      'index' => 1,
      'time' => '11:39:16',
      'timeE' => 1652524756,
      'type' => 'Low',
      'height' => '1.3m',
      'diff' => '1day 8hrs',
    ),
    2 => 
    array (
      'index' => 2,
      'time' => '17:43:49',
      'timeE' => 1652546629,
      'type' => 'High',
      'height' => '8m',
      'diff' => '1day 2hrs',
    ),
    3 => 
    array (
      'index' => 3,
      'time' => '23:57:31',
      'timeE' => 1652569051,
      'type' => 'Low',
      'height' => '1.2m',
      'diff' => '20hrs 27mins',
    ),
  ),
  '2022-05-15' => 
  array (
    4 => 
    array (
      'index' => 4,
      'time' => '06:02:02',
      'timeE' => 1652590922,
      'type' => 'High',
      'height' => '8.3m',
      'diff' => '14hrs 22mins',
    ),
    5 => 
    array (
      'index' => 5,
      'time' => '12:22:53',
      'timeE' => 1652613773,
      'type' => 'Low',
      'height' => '1m',
      'diff' => '8hrs 2mins',
    ),
    6 => 
    array (
      'index' => 6,
      'time' => '18:26:19',
      'timeE' => 1652635579,
      'type' => 'High',
      'height' => '8.4m',
      'diff' => '1hr 58mins',
    ),
  ),
)

However, what I need, is the output to be re-indexed on each date change

array (
      '2022-05-14' => 
      array (
        0 => 
        array (
          'index' => 0,
          'time' => '05:18:31',
          'timeE' => 1652501911,
          'type' => 'High',
          'height' => '7.9m',
          'diff' => '1day 15hrs',
        ),
        1 => 
        array (
          'index' => 1,
          'time' => '11:39:16',
          'timeE' => 1652524756,
          'type' => 'Low',
          'height' => '1.3m',
          'diff' => '1day 8hrs',
        ),
        2 => 
        array (
          'index' => 2,
          'time' => '17:43:49',
          'timeE' => 1652546629,
          'type' => 'High',
          'height' => '8m',
          'diff' => '1day 2hrs',
        ),
        3 => 
        array (
          'index' => 3,
          'time' => '23:57:31',
          'timeE' => 1652569051,
          'type' => 'Low',
          'height' => '1.2m',
          'diff' => '20hrs 27mins',
        ),
      ),
      '2022-05-15' => 
      array (
        0 => 
        array (
          'index' => 4,
          'time' => '06:02:02',
          'timeE' => 1652590922,
          'type' => 'High',
          'height' => '8.3m',
          'diff' => '14hrs 22mins',
        ),
        1 => 
        array (
          'index' => 5,
          'time' => '12:22:53',
          'timeE' => 1652613773,
          'type' => 'Low',
          'height' => '1m',
          'diff' => '8hrs 2mins',
        ),
        2 => 
        array (
          'index' => 6,
          'time' => '18:26:19',
          'timeE' => 1652635579,
          'type' => 'High',
          'height' => '8.4m',
          'diff' => '1hr 58mins',
        ),
      ),
    )

I have been unable to figure this one out and my searches are coming up short. Appreciate any guidance offered

Bonjour à tous, je suis entrain de faire un bouton supprimer pour supprimer les articles publiés [closed]

J’ai l’erreur suivante :Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘>id ?’ at line 1 in C:xampphtdocssiteEnvoladminsupprimerArticle.php:6 Stack trace: #0 C:xampphtdocssiteEnvoladminsupprimerArticle.php(6): PDO->query(‘SELECT * FROM p…’) #1 {main} thrown in C:xampphtdocssiteEnvoladminsupprimerArticle.php on line 6

Voici le code de ma page de suppresion
`<?php

require_once'connect.php';

    if (isset($_GET['id'])) {
        $req = $bdd->query('SELECT * FROM publication WHERE id = '.$_GET['id']);
        $article = $req->fetch();
        if ($article) {
            $req = $bdd->query('DELETE  FROM publication WHERE id = '.$_GET['id']);
            header('location:index.php');
        } else {
            header('location:index.php');
        }
        
    } 

?>`

Remove multiple occurences of unknown text between tags

I want to use mySQL, or PHP (if too tough in SQL), to get rid of all occurrences of any text between certain strings/tags.
I have a database field that looks like the following:

<chrd>F Gm<br><indx>Here's a little song I wrote You might want to sing it note for note...<br><chrd> Bb C F<br><text>Don't Worry Be Happy<br><text>In every life we have some trouble When you worry you make it double...<br><text>Don't Worry Be Happy

I want to remove the text between the tags <chrd> and <br> (tags included or not). I have tried SELECT substring_index(substring_index(text, '<chrd>', -1), '<br>', 1),'') FROM songs; but returns only the last occurrence ( Bb C F). How can I select all occurrences?
Also, the above returns all the text if there is a song with no chords. I would like it to return empty string.

After I get rid of the chords, I will do multiple REPLACE to remove all the tags, so that I will be left with only the plain text, the lyrics. (This OK, I can do)

Note: I don’t know about regular expressions and procedures

Problems to download excel-list Laravel 9

We have the opportunity to download results as an excel-file like this: https://imgur.com/w1g3tnB But this doesn’t work here in Laravel 9.
This is how it looks in pdf: https://imgur.com/usjgBgw
I have replaced the create() to download() but hen I got the error

MaatwebsiteExcelExcel::download(): Argument #2 ($fileName) must be of type string, Closure given

in MaatwebsiteExcelRepository:

<?php

namespace AppRepositories;

use AppContractsExcelInterface;
use Excel;

class MaatwebsiteExcelRepository implements ExcelInterface
{
    /**
     * Creates a file based on given data.
     *
     * @param  string $filename
     * @param  array $rows
     * @param  array $args
     * @return object
     */
    public function create($filename, $rows, $args = [])
    {
        $args['title'] = $this->getTitle($args);
        $args['creator'] = $this->getCreator($args);
        $args['company'] = $this->getCompany($args);
        $args['description'] = $this->getDescription($args);
        $args['keywords'] = $this->getKeywords($args);

        $filenameParts = pathinfo($filename);
        $filename = $filenameParts['filename'];

**COMMENT Next line gives the error**
        return Excel::download($filename, function ($excel) use ($rows, $args) {
            $excel->setTitle($args['title']);
            $excel->setCreator($args['creator']);
            $excel->setCompany($args['company']);
            $excel->setDescription($args['description']);
            $excel->setKeywords($args['keywords']);

            if (count($rows) === 0) {
                $rows[0] = [];
            }

            $excel->sheet('sheet1', function ($sheet) use ($rows) {

                // Make the header row bold.
                $sheet->cells('1:1', function ($cells) {
                    $cells->setFontWeight('bold');
                });

                if (! empty($rows[0])) {

                    // Make sure all columns in the rows are strings.
                    foreach ($rows as $rowIndex => $row) {
                        if (! empty($row) && is_array($row)) {
                            $rows[$rowIndex] = array_map('strval', $row);
                        } else {
                            $rows[$rowIndex] = $row;
                        }
                    }
                }

                $sheet->fromArray($rows);
            });

            // Create an empty second sheet, which is the default for most excel files.
            $excel->sheet('sheet2', function ($sheet) use ($rows) {
            });
        });
    }

So this:

return Excel::download($filename, function ($excel) use ($rows, $args)

must be rearranged in a way.
But how?
As before this works in Laravel 5.3

Eloquent formatting data with __get

I’m quite new to PHP / Eloquent in general and I’m trying to make a little data formatter in my Model class.

public function __get($key)
{
    switch ($key) {
        case "preferred":
            $this->attributes[$key . "_formatted"] = ($this->getAttribute($key) == 1) ? "Yes" : "No";
            break;
    }

    return parent::__get($key);
}

which works fine, it formats the data I want it to format. Thought when I want to $model->update() I get the error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'preferred_formatted' in 'field list' 

Is there a way so I can make it so when I update my $model it doesn’t look for preferred_formatted.
I’ve tried making it hidden but to no avail, I’ve also tried some different solutions but at this point I’m not sure if there’s a better way to format data or if I’m doing something wrong, any help is appreciated.