dimanche 4 juillet 2021

MethodNotAllowedHttpException When i'm using Post Method [gloudemans-package]

recently I'm trying to create a shopping cart for my assignment project. I'm quite new to this framework, sorry if I asked something stupid :( It's a pleasure for me if you guys can check it for me. Tks

I'm also trying to switch to GET method but still didn't work

The error were:

 MethodNotAllowedHttpException

This is my controller

public function cart() {

    if (Request::isMethod('post')) {
        $product_id = Request::get('product_id');
        $product = Product::find($product_id);
        Cart::add(array('id' => $product_id, 'name' => $product->name, 'qty' => 1, 'price' => $product->price));
    }
    if (Request::get('product_id') && (Request::get('increment')) == 1) {
        $rowId = Cart::search(array('id' => Request::get('product_id')));
        $item = Cart::get($rowId[0]);

        Cart::update($rowId[0], $item->qty + 1);
    }
    if (Request::get('product_id') && (Request::get('decrease')) == 1) {
        $rowId = Cart::search(array('id' => Request::get('product_id')));
        $item = Cart::get($rowId[0]);

        Cart::update($rowId[0], $item->qty - 1);
    }

    $cart = Cart::content();

    return view('cart', array('cart' => $cart, 'title' => 'Welcome', 'description' => '', 'page' => 'home'));}

This is my Route

Route::post('cart', 'HomepageController@cart')->name('cart');

This is my view

@extends('layout')
@section('cart')       
<section id="cart_items">
    <div class="container">
        <div class="breadcrumbs">
            <ol class="breadcrumb">
                <li><a href="#">Home</a></li>
                <li class="active">Shopping Cart</li>
            </ol>
        </div>
        <div class="table-responsive cart_info">
            @if(count($cart))
            <table class="table table-condensed">
                <thead>
                    <tr class="cart_menu">
                        <td class="image">Item</td>
                        <td class="description"></td>
                        <td class="price">Price</td>
                        <td class="quantity">Quantity</td>
                        <td class="total">Total</td>
                        <td></td>
                    </tr>
                </thead>
                <tbody>
                    @foreach($cart as $item)
                    <tr>
                        <td class="cart_product">
                            <a href=""><img src="images/cart/one.png" alt=""></a>
                        </td>
                        <td class="cart_description">
                            <h4><a href=""></a></h4>
                            <p>Web ID: </p>
                        </td>
                        <td class="cart_price">
                            <p>$</p>
                        </td>
                        <td class="cart_quantity">
                            <div class="cart_quantity_button">
                                <a class="cart_quantity_up" href=""> + </a>
                                <input class="cart_quantity_input" type="text" name="quantity" value="" autocomplete="off" size="2">
                                <a class="cart_quantity_up" href=''> + </a>
                                <a class="cart_quantity_down" href=''> - </a>
                            </div>
                        </td>
                        <td class="cart_total">
                            <p class="cart_total_price">$</p>
                        </td>
                        <td class="cart_delete">
                            <a class="cart_quantity_delete" href=""><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    @endforeach
                    @else
                <p>You have no items in the shopping cart</p>
                @endif
                </tbody>
            </table>
        </div>
    </div>
</section> <!--/#cart_items-->
@endsection


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3wb21ws
via IFTTT

Laravel MultiAuth [closed]

I have cloned project from one server to another server everything is working good but Auth not working when I try to login page refresh and back same page laravel version is 5.4 and I integrate multi auth Multi auth are: admin shop user



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2V5Co3k
via IFTTT

samedi 3 juillet 2021

Date format changing in vue.js

I'm using date picker :

 <Datepicker :format="format"  v-model="form.start" name="start"></Datepicker>

Its format is something like this :

data(){
        return {
            format: "dd-MM-yyyy",
            form: new Form({
                id:'',
                start: '',

Now on form submit i have appended it to form Data like this

let formData = new FormData();
formData.append('start', this.form.start);

When i console i get date something like this Sat Jul 03 2021 19:11:00 GMT+0530 (India Standard Time)

In the controller i am validating date like :

public function store(Request $request)
    {   
        $this->validate($request, [
            'start' => 'required|date|after_or_equal:'.now()->format('d-m-Y'),

Output:

The start is not a valid date

Any help is highly appreciated.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3qHZEQF
via IFTTT

vendredi 2 juillet 2021

Trying to get property 'servicio' of non-object

I need to print the name of a service, the problem is that it cannot find the column

controller:

public function index(Request $personal){


    $trabajador = Personal::first();
    $personal = Personal::where('nombre' , $personal)->with('nombre')->get();
    $h = Carbon::now(); 
    $servicios = \App\Models\Eventos::orderByDesc('hora')->get();



    $data = [
        'category_name' => 'apps',
        'page_name' => 'calendar',
        'has_scrollspy' => 0,
        'scrollspy_offset' => '',

    ];


    return view('personal', compact('personal', 'servicios', 'h', 'trabajador',))->with($data);

   

  }

blade.php

@foreach ($servicios as $hoy)
    <td></td>
    <td></td>
@endforeach

Model:

 class Personal extends Model
{
    protected $table= 'personal';

    public function servicio()
    {
        return $this->belongsTo(Servicios::class);
    }
}

the relationship in the database is already done

enter image description here

Why can't I print the name of the service? help please



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3yhxKNV
via IFTTT

how to get relation model inside the relation Laravel Eloquent

I want to get the object of the relationship object inside the relationship in laravel i.e

public function skills() {
        return $this->hasMany("App\JobSkill", "object_id", "id")->where('object_type','=', 'j');
    }
    $query->with(['skills' => function ($sql) {
           echo "<pre>";
           print_r($sql->get()->toArray());
           die;
    }])

I use this method but I get all the data of this table instead of this relation object which I defined.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3wcbDHm
via IFTTT

array javascript loop wrong

it´s a simple question but i can´t solve. Always when i tray to do loopp in my array return index 0

<script>
            let status = [];
            let number = [];
            let llamadas = [];
            
            llamadas = {!! json_encode($estados) !!}
            
            for(var i=0; i<llamadas.length; i++){
                console.log(llamadas[i][i]);

                status.push(llamadas[i][i].desc);
                number.push(llamadas[i][i].total)
            }

llamadas its my varaible from controller, i´m working with laravel 5.6 how backend

llamadas contain this:

(7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id_teleoperadora: 9, desc: "APLAZADA", total: 40}
1: {id_teleoperadora: 9, desc: "AUSENTE", total: 132}
2: {id_teleoperadora: 9, desc: "CONFIRMADA", total: 218}
3: {id_teleoperadora: 9, desc: "NUEVA", total: 101}
4: {id_teleoperadora: 9, desc: "NULA", total: 217}
5: {id_teleoperadora: 9, desc: "PENDIENTE", total: 45}
6: {id_teleoperadora: 9, desc: "VENTA", total: 1}
length: 7
__proto__: Array(0)

and his original content content wihtout for

[Array(7)]
0: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
length: 1
__proto__: Array(0)

never i show one array for this way

in push i need extract desc for to build to stadictics with chart.js. now i can return only one state. I don´t know that i´m doing wrong. when i have status i will continue with number but now only i can return one result status "aplazada" i don´t know if i´m doing well my pushs

thanks for help



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2UnGFik
via IFTTT

Why some of date format are not correct in excel sheet in php laravel?

I am exporting csv file one of my column is date but date format get change for some rows i am not getting it why it should be d-m-Y H:i:s but giving d/m/Y H:i:s

enter image description here

here is my code

    $headers = array(
      "Content-type" => "text/csv",
      "Content-Disposition" => "attachment; filename=Consignment Income Invoice.csv",
      "Pragma" => "no-cache",
      "Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
      "Expires" => "0"
    );

    $callback = function () use ($consignments, $sheet_header_columns, $db_columns) {
      $output = fopen("php://output", "wb");
      fputcsv($output, $sheet_header_columns);

      foreach ($consignments as $consignment) {
        $sheet_row = [];
        foreach ($db_columns as $column) {
          if ($column == 'customers') {
            $column_value = $consignment->customers->name;
          } elseif ($column == 'delivery_runs') {
            $column_value =  $consignment->delivery_runs->name ?? '';
          } elseif ($column == 'pickup_address') {
            $column_value =  $consignment->pickup_addresses->full_address ?? '';
          } elseif ($column == 'delivery_address') {
            $column_value =  $consignment->delivery_addresses->full_address ?? '';
          } elseif ($column == 'income') {
            $column_value =  $consignment->charges->sum('income') ?? '';
          } elseif ($column == 'driver_name') {
            $column_value = $consignment->run_sheets->drivers->name ?? '';
          } elseif ($column == 'date_delivered') {
            $column_value =  setDateTimeFormat($consignment->date_delivered);
          } elseif ($column == 'created_at') {
            $column_value = setDateTimeFormat($consignment->created_at);
          } elseif ($column == 'delivery_date') {
            $column_value =  setDateFormat($consignment->delivery_date);
          } else {
            $column_value =   $consignment->$column;
          }
          array_push($sheet_row,$column_value);
        }
        fputcsv($output, $sheet_row); // here you can change delimiter/enclosure
      }

      fclose($output);

    };
    return response()->stream($callback, 200, $headers);

setDateTimeFormat() function

function setDateTimeFormat($date)
{
    if (!empty($date)) {
        $date = date(getDateTimeFormat(), strtotime($date));
        $date = str_replace('-','/',$date);
        if ($date == "01-01-1970 10:00:00") {
            return "";
        }
        return $date;
    } else {
        return "";
    }
}

I set date time formate before exporting it. but still it is changing the format don't know why.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3w6VEKw
via IFTTT