vendredi 21 août 2020

Laravel PHP server throwing 500 error during the attempt to login

Everything was good till yesterday. I added a new column for address in the user table yesterday & since today morning i am unable to login to the server using the credentials. This is the error that i see from laravel.log :

[2020-08-21 12:32:37] development.ERROR: Trying to get property 'name' of non-object (View: /home2/myproject/public_html/shopnow/resources/views/settings/users/profile.blade.php) {"userId":51,"exception":"[object] (ErrorException(code: 0): Trying to get property 'name' of non-object (View: /home2/myproject/public_html/shopnow/resources/views/settings/users/profile.blade.php) at /home2/myproject/public_html/shopnow/storage/framework/views/72651b71bab253e2219bb6bb6d755554a18af965.php:63, ErrorException(code: 0): Trying to get property 'name' of non-object at /home2/myproject/public_html/shopnow/storage/framework/views/72651b71bab253e2219bb6bb6d755554a18af965.php:63)

I realize that its somethign wrong with the "name" property, but not sure what the issue is. I was hoping to get some expert advise here. Can someone please help ?



via Chebli Mohamed

laravel two table value compare , and show value in foreach

laravel compare two table value and show the value in foreach. my code showing error help me to solve this.

i am comparing "delete_status" in both model if "supplier" model delete_status is "NOT_DELETED" it compere titem_list model "delete_status" values if "NOT_DELETED" it will showed items in foreach other showed dont show item.

my controller

public function  totalproduct()
{
    $totalproductlist = DB::table('item_lists')->join('suppliers', 'item_lists.delete_status', '!=', 'suppliers.delete_status')->where('suppliers.delete_status','=','DELETED')->get();
    return view('products.total-product',compact('totalproductlist'));        

}

my model ( Item_list )

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Item_list extends Model
{
     protected $table = 'item_lists';
     protected $fillable = ['product_name','qty','purchase_rate','MRP_rate','sale_rate','supplier_name','part_no'];

}

my model ( Supplier )

<?php

namespace App;
use App\Purchase;
use Illuminate\Database\Eloquent\Model;

class Supplier extends Model
{
     protected $table = 'suppliers';
     protected $fillable = ['party_id','suppliers_master_id','suppliers_unic_id','supplier_name','email','phone','address','city','state','pincode','GSTIN','delete_status','BILL_TYPE'];

    public function items()
    {
        return $this->hasMany(Item_list::class, 'supplier_name', 'supplier_name');
    }
}


via Chebli Mohamed

how to keep Button clicked values and Show Clicked after pressing submit button in laravel

I am trying to select from here

here is my code

<button type="button" data-value="all" @if($session['status']=="all")checked @endif class="btn-status-filter active">All</button>
<button type="button" data-value="sale" @if($session['status']=="sale")checked @endif class="btn-status-filter">Sale</button>
<button type="button" data-value="" @if($session['status']=="rent")checked @endif class="btn-status-filter ">Rent</button>


via Chebli Mohamed

Relationship between user and store

I need to create a relationship between user and many stores. I have created a three models

Store Model

id name email            phone       info
1  xyz  xyz@gmail.com    9329292922  Small Store
2  abc  abc@gmail.com    9494949449  Some Store

User Model

id name email                  
1  ewd  ewd@gmail.com   
2  xcv  xcv@gmail.com    

User_Store

user_id     store_id
   1          1
   1          2

What does the user_store model contain relations whether it is belongstoMany or hasmany?



via Chebli Mohamed

jeudi 20 août 2020

How can I relate BelongsTo with two columns, correctly two Laravel Eloquent models?

I have a base table with two columns, table_name and table_id, yes table name is tablea, the relation should take the table_id and take the TableA model, but if the table_name is tableb, the relation should take table_id to get the relation.

Relations Model Base

   public function tablea()
    {
        return $this->belongsTo(TableA::class, 'table_id')
        ->join('basetable', function($join)
        {
            $join->on('basetable.table_id', '=', 'tablea.id');
            $join->where('basetable.table_name','tablea');
        });
    }

    public function tableb()
    {
        return $this->belongsTo(TableB::class, 'table_id')
        ->join('basetable', function($join)
        {
            $join->on('basetable.table_id', '=', 'tableb.id');
            $join->where('basetable.table_name','tableb');
        });
    }

Controller

BaseModel::with('tablea','tableb')->get();

I have the following code but it always brings me the table_id of TableA, even though in table_name it is tableb. How can I achieve this. ?



via Chebli Mohamed

how to use if / else condition in laravel 5.8 using

I am trying to pass value from view to controller, but it not working. it just triggers normal

my controller public

    function purchaseentryformsave(Request $request) {
      if ($request - > gst == '0') {
        $purchasen = new Purchase;
        $purchasen - > supplier_name = $request - > supplier_name;
        $purchasen - > bill_no = $request - > bill_no;
        $purchasen - > suppliers_master_id = $request - > suppliers_master_id;
        $purchasen - > party_id = $request - > party_id;
        $purchasen - > GSTIN = $request - > GSTIN;
        $purchasen - > bill_date = $request - > bill_date;
        $purchasen - > bill_entry_date = $request - > bill_entry_date;
        $purchasen - > total_bill_amount = $request - > total_bill_amount;
        $purchasen - > phone = $request - > phone;
        $purchasen - > pincode = $request - > pincode;
        $purchasen - > state = $request - > state;
        $purchasen - > address = $request - > address;
        $purchasen - > suppliers_unic_id = $request - > suppliers_unic_id;
        if ($purchasen - > save()) {
          $bill_no = $purchasen - > bill_no;
          $suppliers_master_id = $purchasen - > suppliers_master_id;
          $suppliers_unic_id = $purchasen - > suppliers_unic_id;
          $party_id = $purchasen - > party_id;
          $supplier_name = $purchasen - > supplier_name;
          $GSTIN = $purchasen - > GSTIN;
          $bill_date = $purchasen - > bill_date;
          $bill_entry_date = $purchasen - > bill_entry_date;
          foreach($request - > qty as $k => $p) {
            Billproduct::create(['product_name' => $request['product_name'][$k], 'bill_no' => $bill_no, 'suppliers_master_id' => $suppliers_master_id, 'suppliers_unic_id' => $suppliers_unic_id, 'party_id' => $party_id, 'supplier_name' => $supplier_name, 'GSTIN' => $GSTIN, 'bill_date' => $bill_date, 'bill_entry_date' => $bill_entry_date, 'qty' => $request['qty'][$k], 'HSN_SAC' => $request['HSN_SAC'][$k], 'sale_rate' => $request['sale_rate'][$k], 'MRP_rate' => $request['MRP_rate'][$k], 'purchase_rate' => $request['purchase_rate'][$k], 'part_no' => $request['part_no'][$k], 'dcs' => $request['dcs'][$k], 'gst' => strtoupper('18'), ]);
          }
          foreach($request - > qty as $g => $p) {
            Item_list::create(['supplier_name' => $supplier_name, 'product_name' => $request['product_name'][$g], 'qty' => $request['qty'][$g], 'purchase_rate' => $request['purchase_rate'][$g], 'MRP_rate' => $request['MRP_rate'][$g], 'sale_rate' => $request['sale_rate'][$g], 'part_no' => $request['part_no'][$g], ]);
          }
        }
      }
      elseif($request - > gst != '0') {
        $purchasen = new Purchase;
        $purchasen - > supplier_name = $request - > supplier_name;
        $purchasen - > bill_no = $request - > bill_no;
        $purchasen - > suppliers_master_id = $request - > suppliers_master_id;
        $purchasen - > party_id = $request - > party_id;
        $purchasen - > GSTIN = $request - > GSTIN;
        $purchasen - > bill_date = $request - > bill_date;
        $purchasen - > bill_entry_date = $request - > bill_entry_date;
        $purchasen - > total_bill_amount = $request - > total_bill_amount;
        $purchasen - > phone = $request - > phone;
        $purchasen - > pincode = $request - > pincode;
        $purchasen - > state = $request - > state;
        $purchasen - > address = $request - > address;
        $purchasen - > suppliers_unic_id = $request - > suppliers_unic_id;
        if ($purchasen - > save()) {
          $bill_no = $purchasen - > bill_no;
          $suppliers_master_id = $purchasen - > suppliers_master_id;
          $suppliers_unic_id = $purchasen - > suppliers_unic_id;
          $party_id = $purchasen - > party_id;
          $supplier_name = $purchasen - > supplier_name;
          $GSTIN = $purchasen - > GSTIN;
          $bill_date = $purchasen - > bill_date;
          $bill_entry_date = $purchasen - > bill_entry_date;
          foreach($request - > qty as $k => $p) {
            Billproduct::create(['product_name' => $request['product_name'][$k], 'bill_no' => $bill_no, 
        'suppliers_master_id' => $suppliers_master_id, 'suppliers_unic_id' => $suppliers_unic_id, 
      'party_id' => $party_id, 'supplier_name' => $supplier_name, 'GSTIN' => $GSTIN, 'bill_date' => 
      $bill_date, 'bill_entry_date' => $bill_entry_date, 'qty' => $request['qty'][$k], 'HSN_SAC' => 
     $request['HSN_SAC'][$k], 'sale_rate' => $request['sale_rate'][$k], 'MRP_rate' => 
    $request['MRP_rate'][$k], 'purchase_rate' => $request['purchase_rate'][$k], 'part_no' => 
  $request['part_no'][$k], 'dcs' => $request['dcs'][$k], 'gst' => $request['gst'][$k], ]);
          }
          foreach($request - > qty as $g => $p) {
            Item_list::create(['supplier_name' => $supplier_name, 'product_name' => $request['product_name'][$g], 'qty' => $request['qty'][$g], 'purchase_rate' => $request['purchase_rate'][$g], 'MRP_rate' => $request['MRP_rate'][$g], 'sale_rate' => $request['sale_rate'][$g], 'part_no' => $request['part_no'][$g], ]);
          }
        }
      }
      return redirect('/allpurchasesupplierlist') - > with('success', ' NEW PURCHASE ADDED SUCCESSFULLY .');
    }
    }


via Chebli Mohamed

Calling destroy method in resource controller

I am unable to understand how to call destroy method when I use resource controller in laravel. delete.blade.php

@extends('main')

@section('content')
<form method="POST" action=""  >
@method('DELETE')
@csrf
    <select name="id">
        <option value="1">vddv</option>
        <option value="2">miss</option>
        <option value="3">miss</option>
        <option value="4">joy</option>
    </select>

      <br><br>
    <button type="submit"> Delete blog</button>
</form>
@endsection

resource controller :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\posts;
use Sessions; 


class PostController extends Controller
{ 
    public function create()
    {
        return view('posts.create');   
    }

    public function store(Request $request)
    {
       $post = new posts;
        $post->title = $request->input('title');
        $post->body = $request->input('body');
        $post->save();
        return redirect('posts/read');
    }

    public function show($data)
    {
       echo "show";
    }

    public function edit($id)
    {
        return view('posts.edit');
    }

    public function update(Request $req, $id)
    {
        echo posts::where('title' , $req->title)
        ->update(['body'=>$req->body]);
        return redirect('/');
    }

    public function destroy($id)
    {
        $post = posts::find($id);
        $post->delete();
        return redirect('/');

    }
}

route:

Route::resource('posts', 'PostController');

It is calling show method as it GET request is passed. please guide me how to call destroy method. As mentioned in documentation I am passing @method('DELETE') using form method spoofing as html only recognise GET and POST method.



via Chebli Mohamed