samedi 29 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

dimanche 23 avril 2023

How can I use the variable from php class FinalPrice to javascript class?

I have this function in this location Main/resources/views/dashboards/solicitor/managewills/solicitorclass.php

 var counts = 1;
 var checkboxes;
function add_to_download_entries(data) {
   checkboxes = document.querySelectorAll('input[name="checkWills"]:checked');
    counts = checkboxes.length;
  if($.inArray(data, selected_lostwill_array) >= 0){
    selected_lostwill_array = $.grep(selected_lostwill_array, function(value){
         return value != data;
       });
     }else{
      selected_lostwill_array.push(data);
     }
     // DataTables Functions 
$(document).ready( function () {
    $('#org_lost_table').DataTable();
    $('#all_lost_table').DataTable();
    if(counts>0){
        let finalPrice = "Pay Now $" + Number(counts) * Number(22);
        
        $( "#payment-sub-btn" ).text(finalPrice);
       }else $( "#payment-sub-btn" ).text(0); 
} );
}

I want to use the finalPrice variable value when it updates there to this class at the places where I have let payPrice = 44 - ((44*results['data'])/100); in the place of 44 in location `Main/public_html/js/payment/payment_report.js

function checkCoupon() {
count++;
    var coupon = document.getElementById('lost_coupon').value;
    $.ajax({
        type: "POST",
        url: app_url+"/check_coupon_report",
        data: {
            "_token": csrf_token,
            "coupon": coupon,
        },
        dataType: "json",
        success: function(results) {
        
            if (results['status'] == true  && results['used'] == false) {
                $("#couponMessage").text("Congratulations Your coupon is valid. ");    
                $("#couponMessage").css("color", "green");   
                $("#couponMessage").css("visibility", "visible");   
                let payPrice = 44 - ((44*results['data'])/100);
                $("#couponMessage").append('Your discount is ' +results['data']+'%.' + '<br>Your final price is $' + parseFloat(payPrice.toFixed(2)));
                finalPrice  = parseFloat(payPrice.toFixed(2)) * count;
                $('#payment-sub-btn').text('Pay Now $'+finalPrice);
                console.log(finalPrice);
                if(results['data'] == 100) {
                    $('.card-element-hide').hide();
                    card.destroy();
                    card = null;
                    $('#payment-sub-btn').text('Download Report');
                }
                else{
                $('.card-element-hide').show();
                if(card == null) {
                    createCard();
                    }
            }
            }
        

How can I use the variable from php class FinalPrice to javascript class?



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