dimanche 2 février 2020

laravel shareable form URL

I need to find a way to create a shareable form URL where I can use it to send it to the client(no authentication needed) and the client can fill the form and submit and it would show in my database. My problem with this is not creating the form my problem is how can I create a new shareable form URL that is unique and can only be used once?



via Chebli Mohamed

Displaying Datatables data from a different table

I want to display datatable data from another table inside my master form data.

  1. Company Master File has Employees Tab which is displayed via datatables.
  2. Employees table linked to company via company_id

The relationship already is defined in all Models relevant, I want to use Datatables now to display the employees within the [ Company Employees Tab] inside [Company Master]



via Chebli Mohamed

How to check the last chunk?

i'm using the chunk method chunk to get big data but i need to know the last chunk, because i'm punting the data in file, and at the last chunk i don't want to add something to the file , so i need to know the last chunk

DB::table('users')->chunk(100, function($users)
{
    //how to know if it's the last chunk or not ?
    foreach ($users as $user)
    {
        //
    }
});

is their a way to know the last chunk



via Chebli Mohamed

samedi 1 février 2020

Eloququent: relationship from relationship

Have three tables / models:

Clients:

id - client

Brands:

id - brand

BrandModels:

id - model - brand_id

BrandModelClients:

id - brandmodel_id - client_id

I would like to get a "group by" clients list based on the brands in the cleanest way. Right now, I'm doing it in a dirty way.

So the point is that if I have a client who has three different cars of the same brand, get just one client element.



via Chebli Mohamed

Laravel - Executing command in controller, track progress

I have a system where the user can download a composer package with the click of a button. The installation goes fine and the package gets installed but there is no way to track the progress of the command. I want to track the progress and show it in a progress bar but I don't quite know how to?

Links

<a href="" class="badge badge-light fa-1x">Install</a>
<div class="progress">
    <div class="progress-bar" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
</div>

<a href="" class="badge badge-light fa-1x">Uninstall</a>

Routes

Route::get('package/install', 'PackageController@install')->name('install_package');
Route::get('package/uninstall', 'PackageController@uninstall')->name('uninstall_package');

Controller

public function install()
    {
        $package = new Process("composer require rainieren/visitors");
        $package->setWorkingDirectory(base_path());
        $package->run();

        return redirect('/');
    }

    public function uninstall()
    {
        $package = new Process("composer remove rainieren/visitors");
        $package->setWorkingDirectory(base_path());
        $package->run();

        return redirect('/');
    }

Can this be done? Thanks in advance!



via Chebli Mohamed

How to implement loop on fetched data though group by clause in laravel?

I am trying to implement loop on fetch data but it is giving error that property does not exist.

$SaleOrderProducts = SaleOrderProducts::where('sale_order_id', $id)->get()->groupBy('purchase_order_product.products.id');

I tried this

foreach($SaleOrderProducts as $product)

{
  return $product->products->id;
}

When I just return $products

foreach($SaleOrderProducts as $product)

{
  return $product;
}

then it returns data in this format

[{"id":6,"sale_order_id":2,"product_id":5,"purchase_order_product_id":5,"qty_taken":75,"created_at":"2020-01-31 19:04:05","updated_at":"2020-01-31 22:33:41","purchase_order_product":{"id":5,"purchase_order_id":1,"product_id":5,"measurement_unit":"Cartons","expiry_date":"2020-02-01","created_at":"2020-01-31 19:02:03","updated_at":"2020-01-31 22:33:41","status":1,"initial_qty":454,"on_hand_qty":454,"free_qty":389,"orignal_qty":454,"location":null,"products":{"id":5,"name":"Glass","customer_id":1,"product_type_id":1,"product_status_id":1,"code":"d23123","status":1,"description":"kkd","storage_charge_method":"Per Location","volume":4444554,"weight":545,"random_weight":"Yes","warning_threshold_duration":0,"expiry_threshold_duration":0,"low_stock_notification":"off","low_threshold_duration":null,"stock_selection_method":"Locaiton Efficiency Only","strict_stock_selection":"off","stock_sub_selection_method":"Minimise Storage"}}}]


via Chebli Mohamed

Call to a member function file() on array Error when try to send multiple file()

Laravel says I sent file :

Files

product [ { "mainpic": { "pathname": "/tmp/phpxJefSH", "size": 209982, "mimeType": "image/jpeg" } } ]

Now I tried to get image and upload it with this code in Controller :

$pic = $this->uploadImages($req->file('product')[$key]->file('mainpic'));

Laravel logged this error :

Call to a member function file() on array

and It's from that line of code.

How can I get an image from this uploaded version in the form?



via Chebli Mohamed