dimanche 30 avril 2023

Solving dependecy confilct for upgraing laravel backpack

I'm attempting to upgrade laravel backpack to v3.4.0 guiding by this document.

currently this laravel version is 5.7.x.(yeah it is really outdated project).

in 9th step says run php artisan backpack:base:install, when in run this command this error will be occur :


The command "composer require laracasts/generators:dev-master --dev" failed.           
                                                                                         
  Exit Code: 2(Misuse of shell builtins)                                                 
                                                                                         
  Working directory: /home/user/php/laravel/                             
                                                                                         
  Output:                                                                                
  ================                                                                       
                                                                                         
                                                                                         
  Error Output:                                                                          
  ================                                                                       
  ./composer.json has been updated                                                       
  Running composer update laracasts/generators                                           
  Loading composer repositories with package information                                 
  Updating dependencies                                                                  
  Your requirements could not be resolved to an installable set of packages.             
                                                                                         
    Problem 1                                                                            
      - Root composer.json requires laracasts/generators dev-master -> satisfiable by l  
  aracasts/generators[dev-master].                                                       
      - laracasts/generators dev-master requires illuminate/support ~6.0|~7.0|~8.0|~9.0  
  |^10.0 -> found illuminate/support[v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.  
  0, ..., v8.83.27, v9.0.0, ..., v9.52.7, v10.0.0, ..., v10.9.0] but these were not loa  
  ded, likely because it conflicts with another require.                                 
                                                                                         
  Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removal  
  s for packages currently locked to specific versions.                                  
                                                                                         
  Installation failed, reverting ./composer.json and ./composer.lock to their original   
  content.

In summary laracasts/generators depends on illuminate/support v6.0.0 - v10.9.0 which is not loaded.

how should i solve this conflict?

as error says : i have tried run this command with -W option which is : composer require laracasts/generators:dev-master --dev -W and same error has occured :

- Root composer.json requires laracasts/generators dev-master -> satisfiable by laracasts/generators[dev-master].
    - laracasts/generators dev-master requires illuminate/support ~6.0|~7.0|~8.0|~9.0|^10.0 -> found illuminate/support[v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.7, v10.0.0, ..., v10.9.0] but these were not loaded, likely because it conflicts with another require.
`



via Chebli Mohamed

vendredi 28 avril 2023

How handle a global variable which has changable value in laravel

Suppose we have a variable which must be accessible from all over the laravel app. This variable can be changed by end user.

First I thought it can be defined as a key in one of config files in config directory of laravel and whenever the user change the value of this variable, we can use config::set helper somehow to update the value of this variable in config file.

But the problem is that all config files will be cached in laravel and config::set does not do the job.

I prefer to not use database storage approach.

Any suggestion for solving such a problem?

Thanks in advance,



via Chebli Mohamed

jeudi 27 avril 2023

Install Composer 2.2 on windows

Hey can you help me please with installing composer 2.2 on windows.

I only find the link to install the latest version



via Chebli Mohamed

i have return redirect page but page not reload

i have return redirect page send use with function but not reload page and not show message

my blade file button click:

onclick="edit_offer(,'')"

controller :

return redirect('offer/delete')->with('message','This Service Is Unavailable');

javascript: $.ajax({ method: "GET", url: base_url + '/' + url + '/delete/' + id, success: function (result) { if (result.success == true) { setTimeout(() => { }, 1000); Swal.fire({ type: 'success', title: 'Deleted!', text: 'Record has deleted successfully.', showConfirmButton: false, }) } else if (result.success == false) { alert(result.data); }

            },
            error: function (err) {
                Swal.fire({
                    type: 'error',
                    title: 'Oops...',
                    text: 'This record is connect with another data!'

                })

            }


via Chebli Mohamed

mercredi 26 avril 2023

“vagrant” will damage your computer. | Macos monterey #13132

Today morning suddenly I started getting this popup whenever I ran Vagrant up in my Mac.

enter image description here

Virtualbox Version 7.0.4 r154605 (Qt5.15.2) MACos Monterey, MacBook Pro (Retina, 15-inch, Mid 2015)

Ubuntu LTS Settler Version Homestead Version Branch Status
20.04 11.x 12.x main Development/Unstable
20.04 11.x 12.x release Stable

Do any one have idea whats wrong here?



via Chebli Mohamed

lundi 24 avril 2023

Laravel 5.8: The items.0.id field is required. Error

I am working on an application for the company I work for, this application was made using Laravel 5.8 and MySQL. I have managed to incorporate improvements and so on but there is something that I still can't solve (I'm a junior programmer and I still don't have that much experience). The issue is that there is a many-to-many relationship, I need to make it possible to link new items to the project with their respective quantities in the edit view of a project, in turn it should be possible to unlink previously related items if needed. But nevertheless when trying to do it, the view responds to me with the following error: The items.0.id field is required.The items.0.quantity field is required.

Below the code:

ProjectController:

public function edit($id)
    {
        $project = Project::findOrFail($id);
        $items = Item::all();
        $project_items = $project->items()->pluck('id')->toArray();
        $project_items_quantity = $project->items()->pluck('quantity', 'id')->toArray();
        $item_project = ItemProject::where('project_id', $id)->get();

        return view('includes.edit_delete_project',
            compact('items', 'project_items', 'project_items_quantity', 'item_project'))
            ->with(['project'=> Project::getProjectById($id),
            'entities'=>Entity::getEntities(),
                'countries'=>Country::getCountries()]);
    }

    public function update(Request $request, Project $project)
    {
        $this->validate($request, array(
            'code' => 'required|string|max:255',
            'entity' => 'required|string|max:255',
            'country' => 'required|string|max:255',
            'items' => 'nullable|array',
            'items.*.id' => 'required|integer|exists:items,id',
            'items.*.quantity' => 'required|integer|min:0',
        ));

        $project->update($request->only(['code', 'entity', 'country']));

        if ($request->has('items')) {
            $items = $request->input('items');

            $currentItems = $project->items->pluck('id')->toArray();
            $detachItems = array_diff($currentItems, array_column($items, 'id'));
            $project->items()->detach($detachItems);

            foreach ($items as $item) {
                $project->items()->syncWithoutDetaching([$item['id'] => ['quantity' => $item['quantity']]]);
            }
        }

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

Project Model:

class Project extends Model
{
    protected $table = "project";

    protected $fillable = ['code',
        'entity',
        'country'];
    protected $hidden = ['id'];

    public static function getProjects()
    {
        return Project::all();
    }

    public static function getProjectById($id)
    {
        return Project::find($id);
    }

    public function items()
    {
        return $this->belongsToMany(Item::class, 'project_item',
            'project_id', 'item_id')->withPivot('quantity');
    }
}

Project edit view:

<!-- Edit -->
<div class="modal fade" id="edit">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><b><span class="employee_id">Edit Project</span></b></h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="POST" action="/includes/edit_delete_project/">
                    @csrf
                    <div class="form-group">
                        <label for="code" class="col-sm-3 control-label"><span style="color: red">*</span> Code</label>

                        <div class="col-sm-9">
                            <input oninput="this.value = this.value.toUpperCase()" type="text" class="form-control"
                                   id="code" name="code" value="" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="entity" class="col-sm-3 control-label"><span style="color: red">*</span> Company</label>

                        <div class="col-sm-9">
                            <select class="form-control" id="entity" name="entity" required>
                                <option value="" selected></option>
                                @foreach($entities as $entity)
                                    <option value=""> </option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="country" class="col-sm-3 control-label"><span style="color: red">*</span> Country</label>

                        <div class="col-sm-9">
                            <select class="form-control" id="country" name="country" required>
                                <option value="" selected></option>
                                @foreach($countries as $country)
                                    <option value=""> </option>
                                @endforeach
                            </select>
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="items" class="col-sm-3 control-label"><span style="color: red"></span> Items</label>

                        <div class="col-sm-9">
                            @foreach($items as $item)
                                <div class="form-check">
                                    <input type="checkbox" class="form-check-input" name="items[]" value="" id="item">
                                    <label class="form-check-label" for="item"> - </label>

                                    <input type="number"
                                           class="form-control"
                                           min="1"
                                           style="width: 100px;"
                                           id="quantity_"
                                           name="quantity_"
                                           value="" placeholder="Quantity">
                                </div>
                            @endforeach
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default btn-flat pull-left" data-dismiss="modal"><i
                                class="fa fa-close"></i> Close
                        </button>
                        <button type="submit" class="btn btn-success btn-flat" name="edit"><i class="fa fa-check-square-o"></i>
                            Update
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

I have tried various recommendations from the internet but still have not been successful with any. It is the only thing that I need of all that they asked me to finish the application. I just need to solve what I exposed at the beginning and I will be very grateful to anyone who can help me.



via Chebli Mohamed

samedi 22 avril 2023

sending photos as url by POST method in Laravel 5

I have two projects, A and B. In Project A, I send JSON data along with photo URLs (e.g. http://localhost:8000/images/jWjHlWLwCUz72NAz.jpg) to Project B via a POST method to a specific route (e.g. http://localhost:8002/upload).

I have tried the following:

Sending data without photos from Project A to Project B, which works. Sending data with photos using Postman to Project B, which also works. However, when I try to send JSON data with photo URLs from Project A, I receive the following error after a long time: "ErrorException: file_get_contents(http://localhost:8000/images/jWjHlWLwCUz72NAz.jpg): failed to open stream: HTTP request failed!"

When I try to send the same JSON data using Postman, everything works as expected, and the photos are saved on the disk.



via Chebli Mohamed