AbdulBazith

AbdulBazith

Member Since 1 Year Ago

Tamil Nadu, Tirunelveli

Experience Points 14,580
Experience Level 3

420 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 2
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

26 Jun
13 hours ago

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey thank you sooooo much.

shall i say one thing you are really great..!!!!

exactly what i expected i got it..

thank you thank you soooooooooooo muchhhhh.....

after the query what i did is in my view.blade file

 @foreach($all as $productType => $details)
                @isset($details['totalForType'])
            <tr>

                <td>{{ $details->product_type }}</td>
                <td></td>
                <td>{{ $details['totalForType'] }} </td>

                <td>{{ number_format(($details['totalForType']/ $total_income)  * 100, 2) }}
                    %</td>

            </tr>
            @endisset
            @endforeach

it worked perfectly..

thank you thank youu...

25 Jun
1 day ago

AbdulBazith started a new conversation Delete Records With Relationship And Calculation In Laravel

guys iam facing a problem in my hotel management system.

i have a purchase_order table with columns

id(pk)
purchase_order_no
product_id
qty

after putting an order, when the product arrives from stores then those products to be sent to store.

so i have a from purchase_to_store form and a table name purchase_to_stores with columns

id(pk)
bill_no
total_amount

the above information are filled in the above table.

and i have another table specific_bills where for one bill_no there may be many products with different rates. that are stored in this table. the columns are

id
bill_no_id(fk purchase_to_stores table)
product_id(fk products table)
discount_amt
rate_per_kg
total_amount

after storing in the above table i have stock table where the quantity are stored in that table. when purchase order came from store the data is stored in purchase_to_stores table, specifc_bills table and stock table.

in stock table the products are added when purchase done and subtracted when sales are done.

here whats my doubt is if i delete the record from purchase_to_store table means its related info must be deleted from the specific_bills table and the stocks must also be subtracted from the stock table. how this is possible.

my PurchaseToStore model

 public function specific()
    {
        return $this->hasMany('App\SpecificPurchaseBill', 'bill_no_id');
    }

my SpecificPurchaseBill model

public function PurchaseToStore()
    {
        return $this->belongsTo('App\PurchaseToStore', 'bill_no_id');
    }

my Stock model

 public function product()
    {
        return $this->belongsTo('App\Product', 'product_id');
    }

when i delete my purchase_to_store entry the added stock must also be subtracted. how can i do this?

when creating relationship i did use this line onDelete('cascade');

and i dont have relationship between stock and purchase_to_store. then what can i do??

kindly some one reply.

when i delete a record from one table its relevant tables data with addition subtraction also to be done.

How this is possible.

AbdulBazith left a reply on Groupby And Sum The Total_amount Of Same Suppliers

@kevinbui thank you so much for your response. and sorry for the delay.

ya you are right. the dates may vary. so for that what we can do??

you have edited the code. i still not tried that. but what hapens ??

and if possible kindly refer my another post,

https://laracasts.com/discuss/channels/laravel/fetch-record-from-parent-table-to-child-table-with-its-child-table-in-laravel

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey ok i understood.

can you suggest me one idea please.

if u havesame columns with same fields means what your query will be.

just kindly give me a sql query which combines three tables and sum based on the product_type.

and how to display it in view file. pleaseeee

24 Jun
2 days ago

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey yes.

i have the product_type table with columns

id and

product_type (this was the name of product type) // this is the only column.

here where the names are duplicated??

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey but i dont have two columns with same name..

once again check my columns as i mentioned above.. where there is two columns with same name???

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey no two tables have same column name. see

product_types table (parent table) with columns

id
type_name( for naming convention i changed it like this. but originally this column name is product_type)

products table (child table)

    id
    product_name
        product_type_id (fk)
        product_unit
        product_minimum_qty
        product_rate
        product_rate_type
        note


orders table with columns

    id
        hotel_id
        login_user_id
        purchase_order_id
        bill_no_id
        d_date
        product_id (fk from products table)     
        qty
        total_rate
        rate_per_kg
        gst_percent
        gst_amt
        disc_percent
        disc_amt
        total_amount
        created_at
        updated_at

these are my columns. then whats the problem. i have mentioned all the columns.

my product_type model

public function product()
    {
        return $this->hasMany('App\Product', 'product_type_id');
    }

my product model

 public function product_type()
    {
        return $this->belongsTo('App\ProductType', 'product_type_id');
    }

my order model

public function product()
    {
        return $this->belongsTo('App\Product', 'product_id');
    }

so what can i do??

let me ask another doubt.

if u have the same tables with same columns, means, what you would query to add the same product_type items??

and how will u display it in the view file??

kindly please reply.. dont hesitate

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey yes yes i have product_type "12"

and the product_type table have columns

id
product_type (this is the product_type_name)

23 Jun
3 days ago

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@mthomas @athakur @snapey

can u suggest me based on my code.

mine is working well. the problem is just the

product_type_name is not coming. just it getting

product_type_id.

i will explain my code,

$all = Order::leftJoin('products', 'orders.product_id', '=', 'products.id') ->

  leftJoin('product_types', 'products.product_type_id', '=', 'product_types.id')->get();


it is fetching records what i expected.

dd($all).

Collection {#685 ▼
  #items: array:47 [▼
    0 => Order{#686 ▼
      #fillable: array:16 [▶]
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:25 [▼
        "id" => "12"
        "hotel_id" => "1"
        "login_user_id" => "1"
        "purchase_order_id" => "1377"
        "bill_no_id" => "359"
        "d_date" => "2019-06-01"
        "product_id" => "228"
        "product_type" => "VEGETABLES"
        "qty" => "13"
        "total_rate" => "195"
        "rate_per_kg" => "15"
        "gst_percent" => "0"
        "gst_amt" => "0"
        "disc_percent" => "0"
        "disc_amt" => "0"
        "total_amount" => "195"
        "created_at" => "2019-03-21 11:58:40"
        "updated_at" => "2019-03-21 11:58:40"
        "product_name" => "KEERAI KATTU"
        "product_type_id" => "12"
        "product_unit" => "kg"
        "product_minimum_qty" => "50"
        "product_rate" => "7"
        "product_rate_type" => "changeable"
        "note" => null
      ]
      #original: array:25 [▶]
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #events: []
      #observables: []
      #relations: []

in the above code just i picked the values and mention below

// these are values from Order table

 "id" => "12"
        "hotel_id" => "1"
        "login_user_id" => "1"
        "purchase_order_id" => "1377"
        "bill_no_id" => "359"
        "d_date" => "2019-06-01"
        "product_id" => "228"
        "product_type" => "VEGETABLES"
        "qty" => "13"
        "total_rate" => "195"
        "rate_per_kg" => "15"
        "gst_percent" => "0"
        "gst_amt" => "0"
        "disc_percent" => "0"
        "disc_amt" => "0"
        "total_amount" => "195"
        "created_at" => "2019-03-21 11:58:40"
        "updated_at" => "2019-03-21 11:58:40"

//these are values from products table

        "product_name" => "KEERAI KATTU"
        "product_type_id" => "12"
        "product_unit" => "kg"
        "product_minimum_qty" => "50"
        "product_rate" => "7"
        "product_rate_type" => "changeable"
        "note" => null

so based on the above product_type_id, the values are added.

i used these below codes for adding based on product_type. why i used these because, i had a doubt in my old project. so someone in this forum suggested these codes, but that old project need such type of code. i copy pasted the same code and used here. i think these is too complicated code. how i can do this??

i followed this link only: https://laracasts.com/discuss/channels/laravel/need-a-logical-help-in-viewblade-file

$pro_cat = [];

  $total_purchase = 0;  
  
  foreach ($all as $key => $al)
   {
   $pro_cat[$al->product_type_id]["total_amount"] = 0;
  }

  foreach ($all as $key => $al) {
   $pro_cat[$al->product_type_id]["total_amount"] += $al->total_amount;

   $total_purchase = 0;
   foreach ($pro_cat as $item) {
    $total_purchase += $item['total_amount'];
   }

  }


i was so confused about the array structure of laravel

i know about get() and paginate(). simple foreach is enough.

but when it comes to groupby, sum or other something the values are inside the array structre. i can get the values by checking it in dd(); but i dont know how to displya it in blade file

thats my biggest problem. kindly suggest a solution for this question and also share me some links of array structure of laravel in blade file.

in this question everything is clear. just i need the product_type name instead of id.

@snapey @mthomas @athakur

Kindly reply pleaseee

22 Jun
4 days ago

AbdulBazith left a reply on Groupby And Sum The Total_amount Of Same Suppliers

@kevinbui thank you soo much for your response..

i tried your coding it works.

but i have a small problem in this line

@foreach($suppliers as $supplier)
    <tr>
        <td>{{$supplier->id}}</td>
        <td>{{$supplier->name}}</td>
        <td>{{$supplier->payments->sum('amount')}}</td>
    </tr>
@endforeach

i need to display the due_date the column is in purchase_to_store table.

if i need to display the records from purchasetostore table means what should i doo??

i tried

  <td>{{$supplier->payments->due_date}}</td> // u changed the model name for naming convention 

it shows error

Property [due_date] does not exist on this collection instance. 

whats the issue??

AbdulBazith started a new conversation Groupby And Sum The Total_amount Of Same Suppliers

guys i have a small problem in my hotelmanagement system. its a erp like software.

i have a table purchase_to_stores with columns

id
supplier_id (fk)
due_date
bill_no
total_amount
payment_status
payment_date

i need to fetch records from this table, with a where condition between two date of due_date and total_amount should be added if supplier_id is same.

that is for one supplier i may bought 2 bill_no. 1 bill for rs 500 and another bill ofr rs 200. so i need to get the output as

the due_date, supplier_name, total_amount must be 700 .. like this

this is my supplier model,

 public function purchasetostore()
    {
        return $this->hasMany('App\PurchaseToStore', 'supplier_id');
    }

this is my PurchaseToStore model

 public function supplier()
    {
        return $this->belongsTo('App\Supplier', 'supplier_id');
    }

my query is

$paymentlists = PurchaseToStore::where('payment_status', '0')->whereBetween('due_date', array($fromdate, $todate))->paginate(50);

and in my view.blade file

 <thead>
                                        <tr>
                                            <th>S.No</th>
                                            <th>Due Date</th>
                                            <th>Supplier</th>
                                            <th>Cheque or Cash</th>
                                            <th>Amount</th>
                                            <th>Signature</th>
                                        </tr>
                                    </thead>


 @foreach($paymentlists as $s_no=>$paymentlist)
                                        <tr>
                                            <td >
                                                {{ $s_no + $paymentlists->firstItem() }}
                    </td>

                                        <td >
                                                {{ \Carbon\Carbon::parse( $paymentlist->due_date)->format('d-m-Y') }}                                        
                                       </td>

                                            <td >
                                                {{ $paymentlist->supplier->sup_name }}
                    </td>

                                            <td >
                        </td>

                                            <td >{{ $paymentlist->total_amount }}</td>
                                            <td> </td>

                                        </tr>

 @endforeach

i can get the output. but if a supplier has two bills. then the two bills are displayed. I need the total amount for same supplier.

what to do kindly some one help

21 Jun
5 days ago

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@mthomas

i tried

$all=Order::with(['products.product_types' => function($query){
        $query->groupBy('id');
    }])->get();
    
    dd($all);

it shows an error

Call to undefined relationship [products] on model [App\Order].

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@mthomas thank you for your response..

sorry i didnt notice your response.. let me try it and reply

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey that only i cant understand..

actually when i give dd($all) records from order table and records from product table are displayed, but records from product_type table is not displayed..

let me shrink the query,

$all = Order::leftJoin('products', 'orders.product_id', '=', 'products.id') ->

  leftJoin('product_types', 'products.product_type_id', '=', 'product_types.id')->get();

the above is the actual query

these are my tables orders, products and product_types

now the dd() displays the records of order and product table. not the product_type table.

20 Jun
6 days ago

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey thank you for your response. but it is grouping by ts product_type_id

actually i can get everthing. just i need to display the name of product-type instead product_type_id..

if i change

my view into

@foreach($pro_cat as $productType => $details)
                                            @isset($details['total_amount'])
                                        <tr>

                                            <td>{{ $productType->product_type->product->type }}</td> //as per my product and product_type model
                                            <td></td>
                                            <td>{{ $details['total_amount'] }} </td>
                                            <td>{{ number_format(($details['total_amount']/ $total_income)  * 100, 2) }}
                                                %</td>

                                        </tr>
                                        @endisset
                                        @endforeach


but it shows error, undefined error product_type

i can get the product_type_id by using the query



 $all = Order::where('hotel_id', Auth::user()->hotel_id)->

  whereHas('PurchaseToStore', function ($query) use ($request)

 {

    $query->latest()->where('payment_status', 1)->whereBetween('payment_date', [$request->from_date, $request->to_date]);
})


  ->leftJoin('products', 'order.product_id', '=', 'products.id') ->

  leftJoin('product_types', 'products.product_type_id', '=', 'product_types.id')->get();



but the product_type name???

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey Kindly give me an idea please...

19 Jun
1 week ago

AbdulBazith left a reply on Get Data From 3 Tables With Relationship Laravel

@snapey thank you soo much for your response..

i tried with joins,

see this


// in this below query what iam doing is fetching records from from order table where payment status of purchaseToStore must be '1' and then i gave the join query..



 $all = Order::where('hotel_id', Auth::user()->hotel_id)->

  whereHas('PurchaseToStore', function ($query) use ($request)

 {

    $query->latest()->where('payment_status', 1)->whereBetween('payment_date', [$request->from_date, $request->to_date]);
})


  ->leftJoin('products', 'specific_purchase_bills.product_id', '=', 'products.id') ->

  leftJoin('product_types', 'products.product_type_id', '=', 'product_types.id')->get();





//after getting the records $all from order table, i tried to add the total amount with product_type_id. after that i added the overall total.





 $pro_cat = [];

  $total_purchase = 0;
  
  
  foreach ($all as $key => $al)
   {

   $pro_cat[$al->product_type_id]["total_amount"] = 0;

  }

  foreach ($all as $key => $al) {
   $pro_cat[$al->product_type_id]["total_amount"] += $al->total_amount;

   $total_purchase = 0;
   foreach ($pro_cat as $item) {
    $total_purchase += $item['total_amount'];


   }



  }


when i give dd($all); the result is

Collection {#681 ▼
  #items: array:47 [▼
    0 => SpecificPurchaseBill {#682 ▼
      #fillable: array:16 [▶]
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:25 [▶]
      #original: array:25 [▼
        "id" => "12"
        "hotel_id" => "1"
        "login_user_id" => "1"
        "purchase_order_id" => "1377"
        "bill_no_id" => "359"
        "d_date" => "2019-06-01"
        "product_id" => "228"
        "product_type" => "VEGETABLES"
        "qty" => "13"
        "total_rate" => "195"
        "rate_per_kg" => "15"
        "gst_percent" => "0"
        "gst_amt" => "0"
        "disc_percent" => "0"
        "disc_amt" => "0"
        "total_amount" => "195"
        "created_at" => "2019-03-21 11:58:40"
        "updated_at" => "2019-03-21 11:58:40"
        "product_name" => "KEERAI KATTU"
        "product_type_id" => "12"
        "product_unit" => "kg"
        "product_minimum_qty" => "50"
        "product_rate" => "7"
        "product_rate_type" => "changeable"
        "note" => null
      ]
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #events: []
      #observables: []
      #relations: []

and when i dd($pro_cat); the result is

array:14 [▼
  12 => array:1 [▼
    "total_amount" => 6295
  ]
  26 => array:1 [▼
    "total_amount" => 1250
  ]
  13 => array:1 [▼
    "total_amount" => 340
  ]
  27 => array:1 [▼
    "total_amount" => 1700
  ]
  14 => array:1 [▼
    "total_amount" => 315
  ]
  37 => array:1 [▼
    "total_amount" => 4056
  ]
  11 => array:1 [▶]
  32 => array:1 [▶]
  9 => array:1 [▶]
  29 => array:1 [▶]
  2 => array:1 [▶]
  1 => array:1 [▶]
  31 => array:1 [▶]
  20 => array:1 [▶]
]


the above coding working fine. what i expect i got the result.

but the problem is, the product_type_id is displayed in the view file.

this is my view file

  @foreach($pro_cat as $productType => $details)
                                            @isset($details['total_amount'])
                                        <tr>

                                            <td>{{ $productType }}</td>
                                            <td></td>
                                            <td>{{ $details['total_amount'] }} </td>
                                            <td>{{ number_format(($details['total_amount']/ $total_income)  * 100, 2) }}
                                                %</td>

                                        </tr>
                                        @endisset
                                        @endforeach

Refer the screenshot for my output image: https://imgur.com/fR4sqeS

see the product_type_id is displayed. i need the product name.. how to do this??

and what i answered is what i did?? else i made the code tooo complicated??

AbdulBazith started a new conversation Fetch Record From Parent Table To Child Table With Its Child Table In Laravel

Guys i have a problem in my hotel management system project.

i have a product_type table (parent table) with columns

id
type_name

product table (child table)

id
product_type_id(fk)
product_name

order_table with columns

id
product_id(fk)
qty
rate
total

here whats my doubt is i need to fetch records from order_table. but the record must be grouped by the product_type. how can i achieve it.

the product_type and product has relationship

this is my product model

 public function product_type()
    {
        return $this->belongsTo('App\ProductType', 'product_type_id');
    }

this is my product_type model

 public function product_type()
    {
        return $this->belongsTo('App\ProductType', 'product_type_id');
    }

this is my query,

 $order = Order::where ('hotel_id',Auth::user()->hotel_id)->get();

i need to fetch records based the product_type wise. it mus be grouped based on product_type.

Kindly some one help please.

14 Jun
1 week ago

AbdulBazith left a reply on How To Add/remove Duplicate A Set Of Input Fields Inside A Div Tag Javascript

@johnbraun thank you soo much for you response..

no iam not using vue.js.

i need it to work with js only. is it possible?? can you suggest any link please??

12 Jun
2 weeks ago

AbdulBazith started a new conversation How To Add/remove Duplicate A Set Of Input Fields Inside A Div Tag Javascript

Guys iam working with a project, school Management System,

i have a two text boxes inside a div tag, and also have a add button.

if i click the add button another set must be generated, that is the div tag must be duplicated, for entering another set of records with different unique id for that div tag. if user not need that then when the div tag is duplicated with it a delete button must also displayed, if we click that the div tag should be removed or erased.

this is my div tag

<div id="fee" name="fee" class="design1">

<div class="col-sm-6">
    <div class="form-group">
        <label class="control-label">Sub Cat </label>
        <input type="text" name="sub_cat_name[]" id="sub_cat_name[]" class="form-control" />
    </div><!-- form-group -->
</div>

<div class="col-sm-6">
    <div class="form-group">
        <label class="control-label">Amount</label>
        <input type="text" name="sub_cat_amt[]" id="sub_cat_amt[]" class="form-control" />
    </div><!-- form-group -->
</div>

</div>

the label <label class="control-label">Sub Cat </label> must change like sub cat 1, sub cat 2 like that when we click the add button. if needed the div tag can be deleted also.

how this is possible kindly suggest your idea..

07 Jun
2 weeks ago

AbdulBazith left a reply on Problem In Table Structure For Fees Structure In School Project

@munazzil thank you for your reply. but thats not my doubt,

already i have kept like that only.

my problem is the table structure..

06 Jun
2 weeks ago

AbdulBazith started a new conversation Problem In Table Structure For Fees Structure In School Project

Guys iam working with a new project SchoolManagementSystem

i need to make a fee structure form.

the fee is differentiated into main category and sub category.

for example TermFee1 is main category, and it be sub categorized into two TutionFee and BookFee.

so i have a form and a table to add the main category alone.

now iam going to make another for for the fee structure.

this is the form refer: https://imgur.com/knOV5ye

In the above image, class is chose from class table, fee main category is chose from that table, start date chose end due date chose. below i have two sections sub cat 1 with amt, and sub cat2 with amt, below that i will have a button (presently not in the screen shot) to add further sub categories like sub cat3,.. so on. at-last the total amount is displayed, and then will fill the note these details must be added to the table.

is the form is right?? else need to change ??

this is table structure for my fee structure

  $table->bigIncrements('id');
            $table->bigInteger('class_id')->unsigned();
            $table->foreign('class_id')->references('id')->on('add_class_sections')->onDelete('cascade');
            $table->bigInteger('fee_main_cat_id')->unsigned();
            $table->foreign('fee_main_cat_id')->references('id')->on('fee_main_categories')->onDelete('cascade');
            $table->date('due_start_date');
            $table->date('due_end_date');
            $table->string('sub_cat_name');
            $table->bigInteger('sub_cat_amt');
            $table->longText('note');
            $table->timestamps();

the screen shot for my table struture is : https://imgur.com/yoXQpBJ

Another view of my fee structure table : https://imgur.com/p3sibgn

This is the table structure for my fee structure.

is this right??

if a main category has more than one sub cat then it is inserted and multiple rows.

but i cant place the total_amount column??

i was confused about the table i created was right??

why this problem because, making this application dynamic for different school, so some school may have two sub categoreies, some school may have 5 sub categories, like wise,

is the table structure is right??

Kindly some one help and suggest you ideas, if possible share any reference link please

AbdulBazith left a reply on Error In Creating Table With Foreign Key Constrain In Migration

@ftiersch thank you soo much for your response.

it worked. just changed,

from,

$table->integer('year_id')->unsigned();

to,

$table->bigInteger('year_id')->unsigned();

it worked.. thank you..

04 Jun
3 weeks ago

AbdulBazith started a new conversation Error In Creating Table With Foreign Key Constrain In Migration

Guys i have started a new project schoolMangementsystem

this is my db SchoolManagementSystem

i have a table add_years to add academic years like 2019-2020

now iam going to create a table add_class_sections

so i gave

php artisan make:model AddClassSection --migration

the model and migration file created succesfully.

after that in the migration file i filled the columns

  Schema::create('add_class_sections', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('year_id')->unsigned();
            $table->foreign('year_id')->references('id')->on('add_years')->onDelete('cascade');
            $table->string('class');
            $table->string('section');
            $table->longText('note');
            $table->timestamps();
        });

if i give php artisan migrate it shows error

 Illuminate\Database\QueryException  : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users` (`id` bigint u
nsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) not null, `email_verified_at` timestamp null, `password` varchar(255) no
t null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at C:\xampp\htdocs\Laravel\SchoolManagementSystem\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists")
      C:\xampp\htdocs\Laravel\SchoolManagementSystem\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458

  2   PDOStatement::execute()
      C:\xampp\htdocs\Laravel\SchoolManagementSystem\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458

  Please use the argument -v to see more details.


I thought that users table migration file is the issue so i cut the file from the migration location and pasted it another folder.

after that i deleted the model, migration file and gave composer dump-autoload -o

then once again created the migration file to add the class_section with same model then i did the same process

now it shows another error

Migrating: 2019_06_04_071000_create_add_class_sections_table

   Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1005 Can't create table `schoolmanagementsystem`.`#sql-1778_cd` (errno: 150 "Foreign key constr
aint is incorrectly formed") (SQL: alter table `add_class_sections` add constraint `add_class_sections_year_id_foreign` foreign key (`year_id`) references `add_years` (
`id`) on delete cascade)

  at C:\xampp\htdocs\Laravel\SchoolManagementSystem\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `schoolmanagementsystem`.`#sql-1778_cd` (errno: 150 "Foreign key constraint is incorrectly
 formed")")
      C:\xampp\htdocs\Laravel\SchoolManagementSystem\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458

  2   PDOStatement::execute()
      C:\xampp\htdocs\Laravel\SchoolManagementSystem\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458

  Please use the argument -v to see more details.


whats the problem here??

what should i do??

Kindly some one help please..

AbdulBazith left a reply on Retrieving Records From Child Table With Where Condition In Parent Table

@kevinbui thank you thank you so much for your response.

you are exactly right.

just now i too found that.

AbdulBazith started a new conversation Retrieving Records From Child Table With Where Condition In Parent Table

Guys i have a doubt

this is is my parent table purchase_to_stores with columns

hotel_id
bill_no
total_amount
payment_status
payment_date

if a generate a bill no with 'B1' like onion 40 rupees, tomato 30 rupees. in the parent table it is filled with

hotel_id        bill_no     total_amount    payment_status          payment_date
Hotel1      B1              70          1                   04/062019

and this is my child table specific_purchase_bills with columns

hotel_id (fk)
bill_no_id (fk parent table 'purchase_to_stores')
product_id
total_amount

in the above table the price of onion and price of tomato are filled as two rows for that specific bill no.

now i have retrieve the records form the child table specific_purchase_bills with a where condition of payment_status="1" in the parent table purchase_to_stores

How this is possible.

what i did is.

 $all = SpecificPurchaseBill::where('hotel_id', Auth::user()->hotel_id)->
   where(function ($query) use ($request) {
  
   if (!empty($request->from_date)) {
    $query->whereBetween('d_date', [$request->from_date, $request->to_date]);


   }

  })->orderBy('created_at', 'asc')->get();

this fetches all records within given date in the child table specific_purchase_bills. but i need the condition from the parent table with payment_status= "1". bill_no is the common for both table.

i tried with different coding but the problem is. i need to use more than 2 for loops and 2 if conditions, i know that iam somewhere wrong, but i cant get it,

Kindly some one help

20 May
1 month ago

AbdulBazith left a reply on How To Make Form And Db As Dynamic Based On User Requirement In Laravel

@devfrey thank you for you response.

you are right. i must reduce my question length.

Let me work with it and come with narrow down question.

thank you for your suggestion.

16 May
1 month ago

AbdulBazith left a reply on How To Delete Records With Relationship With Multiple Tables

@nasmed thank you so much, i forgot to mention the relationship in the model.

now it worked correctly. thank you soo much.

i have another doubt,

as already i asked if i have calculation means what can i do?

in the above PurchaseOrder and OrderList. there is no calculation just based on it deleted successfully.

think the same example with same PurchaseOrder and OrderList

when i add a purchase order for example Onion, means if the onion exist in the orderList table then the quantity will be added.

that is if Onion in orderList table qty is 10, iam making a PurchaseOrder with 36 means. then it will added as 46 in OrderList.

now if delete the PurchaseOrder for this onion. it must be deleted in the PurchaseOrder table and the qty 36 also must be subtracted from the OrderList table

How this is possible.

15 May
1 month ago

AbdulBazith left a reply on How To Delete Records With Relationship With Multiple Tables

@nasmed sorry for the delay..

i tried this code


  protected static function boot()
    {
        parent::boot();

        self::deleting(function ($purchaseOrder) {
           $purchaseOrder->orderLists->each->delete();
        });

    }

here what is $purchaseOrder->orderLists->each->delete(); this line indicates here what is OrderLists

this was the error


Trying to get property 'each' of non-object

14 May
1 month ago

AbdulBazith started a new conversation How To Make Form And Db As Dynamic Based On User Requirement In Laravel

Guys i have a problem in starting my new project.

i need to make an application for a school to manage their students profile, staff profile and fee payment and salary payment.

now what i planned is to make a tool which can be useful for all the schools,

but all school will not follow the same procedure.

some schools will get only few information about the student at the time of admission,

some school will get more information about the student during admission.

so form must be flexible that they can add additional information if needed. and based on that db must lso be dynamic.

at the same time the fee payment varies from one school to another school.

some school will make the fee payment in three terms in which each term may be categorized in to two types like tuition fee and books fee.

but in some school the make the fee payment in three terms but they may be categorizes into 4 types like tuition fee, book fee, van fee and lab fee.

this must also be flexible based on the school to school. based on the dynamic form, the db must also be dynamic.

how this is possible??

kindly some one help please??

i already asked this question with clear explanation

refer: https://laracasts.com/discuss/channels/laravel/how-to-make-database-dynamic-based-on-user-selection-in-forms-laravel

but no one answered.

kindly some one suggest you ideas, i was so confused, how to do this?? is there any easy way in laravel??

else do i need to create tables while run time??

else is there some other way??

Kindly please some one help. suggest your ideas.

if possible kindly share any tutorial link. please..

Whats my biggest doubt is, if the school adds extra fields for fee payment or for admission, then what hapens in db??

will a new column will be created or it will inserted and a new row.

iam fully blank, so kindly suggest your ideas please.. ...

13 May
1 month ago

AbdulBazith left a reply on How To Make Database Dynamic Based On User Selection In Forms Laravel

@snapey

Kindly give your suggestion for this question please..

11 May
1 month ago
10 May
1 month ago

AbdulBazith left a reply on Problem With Adding Same Id Values In View.blade File

@snapey thank you for you response.

i used like this


                                        <tr>

                                            <td width="20%">{{ $income->income_type->income_type  ?? '---' }}</td>
                                            <td width="20%">{{ $income->income_amount  ?? '---' }}</td>
                                            <td></td>
                                            <td></td>
                                        </tr>

the out put is refer: https://imgur.com/bmoD1aP

why it became all dashes. why the particulars are not displayed. whats the problem. the amount also not displayed. but i have these...

i need the name of income types particulars

if i give dd($incomes); means it shows

array:6 [▼
  "ROOM SERVICE" => 29
  "ROOM BILL" => 36
  "BAGS INCOME" => 580
  "PARCEL" => 85
  "TIFFIN" => 120
  "A/C SALES" => 500
]



the above mentioned are the particulars.

in the image i show you.

in the particulars column the name ROOM SERVICE and so on must be displayed,

and in the Income column 29 the amount must be displayed.

Expecting like this

Particulars             Income

ROOM SERVICE            29
ROOM BILL               36
BAGS INCOME         580
PARCEL                  85
TIFFIN                  120
A/C SALES               500


Total                   1350

How could i get this???

AbdulBazith started a new conversation How To Make Database Dynamic Based On User Selection In Forms Laravel

Guys iam going to start a new project School Management System(SMS), which handles the modules such as,

1) student (profile, fee, attendance, marks etc).
2)staff (profile, salary, attendance, etc,login).
3)Parent (login, view student info etc).
.
.
.
. 
and so on.

```.

currently i started the student module only. need to complete it before jun 10.

just need to get student info during his admission, and after he was admitted , fee payment should be done , then later after examination his marks to be entered.

now what my doubt is,

the project is for a specific school. so i know the full requirement. so can structure the db based on their requirement.

but what my boss decided is to make the school management system application as a tool which suits for all other different kind of schools.

so for this the structure should be made by the school admin.

say for example consider ```school1 and school2```

the both have different admission procedure.

basically all school will collect student fname, lname, DOB, Dateof joining, parent name, phno, blood group, address, etc.

the above mentioned are basic info that all school will collect.

but other then this, think that, school1 will collect only these info.

but school2 will collect extra more info.

so the form must be flexible for this school1 and school2 also.

that is if school2 needs to add  extra field about student, then let them have a add button in form using js additional column will be added, but in db how it could be structured, that it must be flexible for any type of school.

same problem in Fee payment.

school1 has ```TermFee1->books+tution Fee, TermFee2->books+ tutionfee``` like this

but school2 have ```TermFee1->books+tutionFee+ transportFee+LabFee,``` same for TermFee2 also


so the fee structure also carries for different school.

My application should be flexible for both the school. what should i do for this?

Db is the big problem here.  how it varies for different school.


i will also mention the fee structure  what i planned. just roughly i planned. is it correct.

Have a form with


class

Name of the Fee

structure (divide) of the name.

Add (button)


so first the school admin need to structure the fee form.

Name of the class: 1st std

Name of the fee: TermFee1

structure (divide) of the name1: Book Fee

structure (divide) of the name2 : Tuition Fee


now structure is defined.

so when admin comes to enter the fee form,

it asks

name of the class: when admin select the class,

then automatically, name of the fee will be filled in drop down: if admin selects  TermFee1

then in next  two text box it must be labeled with Book fee and Tuition Fee.  so when admin enters the fee thte total must be displayed.

this will be different for School2.

so this is what the problem.

the form must be structured based on the school. the admin of the school can structure the form.

but db how it is possible..??

I think all may have experience in such type of application.

so kindly do share your ideas please..

and if possible kindly share any video tutorial link or any other link which helps me a lot please.


kindly everyone suggest your ideas please.

AbdulBazith left a reply on How To Delete Records With Relationship With Multiple Tables

@nasmed thank you so much for you response.

but i have calculation also.

for that what can i do??

as i mentioned for the

if i add a product to store, say rice 40 kg 4000 rupees then it will be added to the store and also the amount will be updated to that supplier in supplier_amount table.

AbdulBazith left a reply on Problem With Adding Same Id Values In View.blade File

@vandan29 thank you so mu ch for your response.

noo it not worked.

09 May
1 month ago

AbdulBazith started a new conversation Problem With Adding Same Id Values In View.blade File

Guys i have two tables, income_type and income

income_type consist of fields

id
income_type

and income table consist of fields

id
hotel_id
income_date
income_type_id(fk income_type table)
income_amount

so i have three hotels entry in these tables.

now i need to add the total of three hotels for each income_type id.

that is parcel income_type for hotel1 is 300, for hotel2 is 400 means then parcel - 700 like this i need,

so what i did is

used groupby

  $data = Income::where('income_date', $request->search_date)->with('income_type')->get()->groupBy('income_type_id');


 $incomes = [];

  foreach ($data as $key => $item)

  {

   $incomes[$item[0]['income_type']['income_type']] = collect($item)->sum('income_amount');

   $total_income = 0;

   foreach ($incomes as $item) {


    $total_income += $item;

   }


  }



if i give dd($incomes); means it shows

array:6 [▼
  "ROOM SERVICE" => 29
  "ROOM BILL" => 36
  "BAGS INCOME" => 580
  "PARCEL" => 85
  "TIFFIN" => 120
  "A/C SALES" => 500
]

here how this output came is ```ROOM SERVICE => 29 means hotel1 room service 10+hotel2 roomservice 10 + hotel3 roomservice 9 .

like this all the other also came.

and why i used this means the below

 $total_income = 0;

   foreach ($incomes as $item) {


    $total_income += $item;

   }

the dd( $total_income); 1350 the total of all the above.

now whats the problem iam facing is how to display this is the view file.

with name and amount.

this is my income_type model

 public function income()
    {
        return $this->hasMany('App\Income', 'income_type_id');
    }

this is my income model

 public function income_type()
    {
        return $this->belongsTo('App\IncomeType', 'income_type_id');
    }

in my blade file what i did is

 <tbody>
                                        <tr>
                                            <td colspan="4" align="left"><b>INCOME SECTION</b></td>
                                        <tr>

                                            @foreach($incomes as $income)
                                        <tr>

                                            <td width="20%">{{ $income }}</td>
                                            <td width="20%">{{ $income_amount }}</td>
                                            <td></td>
                                            <td></td>
                                        </tr>

                                        @endforeach
                                        <tr>
                                            <td colspan="1" align="center">
                                                <b> Total Income Value </b>
                                            </td>
                                            <td>
                                                <b> {{ $total_income }} </b>
                                            </td>
                                            <td colspan="2"></td>

                                        </tr>
                                    </tbody>



this showing error

Trying to get property 'income_type' of non-object (View:   

how can i display the name and the amount.

Kindly some one help.

AbdulBazith left a reply on How To Use Search Option In Drop Down In Array Of Drop Downs Javascript

@lostdreamer_nl

kindly suggest me an idea please.

expecting response from you please.

AbdulBazith started a new conversation How To Delete Records With Relationship With Multiple Tables

Guys my project has a purchase order form.

i have two tables purchase_order_table and order_list_table

both in relationship purchase_order_table is parent tble and order_list is child table.

this is my purchase_order_migration file

 Schema::create('purchase_orders', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('login_user_id')->unsigned();
            $table->foreign('login_user_id')->references('id')->on('users');
            $table->string('pur_order_num');
            $table->integer('supplier_id')->unsigned();
            $table->foreign('supplier_id')->references('id')->on('suppliers');
            $table->date('order_date');
            $table->time('order_time');
            $table->date('expec_date')->nullable();
            $table->time('expec_time')->nullable();
            $table->date('del_date')->nullable();
            $table->time('del_time')->nullable();
            $table->timestamps();
        });

this is my order_list migration file

  Schema::create('order_lists', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('login_user_id')->unsigned();
            $table->foreign('login_user_id')->references('id')->on('users');
            $table->integer('purchase_order_id')->unsigned();
            $table->foreign('purchase_order_id')->references('id')->on('purchase_orders');
            $table->integer('product_id')->unsigned();
            $table->foreign('product_id')->references('id')->on('products');
            $table->bigInteger('qty');
            $table->timestamps();
        });

i didnt use the onDelete('cascade'); in the migration.

now i need to delete record from parent table which in turn must delete all the relevant child table.

how to do this??

i need few calculation also.. those are in other tables.

say for example.

if i add a product to store, say rice 40 kg 4000 rupees then it will be added to the store and also the amount will be updated to that supplier in supplier_amount table.

so when i delete the entry which i made in the store then it should less that 4000 rupees amount amount from the supplier_amount table and also the qnty from the store table.

so how i can i delete a record with relationship with multiple tables.

Kindly some one suggest your ideas please.

AbdulBazith left a reply on Dividing Columns With Barryvdh/laravel-dompdf Laravel

@mvd . thank you so much for your response.

let me try and inform you.'

thank you for your help

06 May
1 month ago

AbdulBazith left a reply on How To Delete Multiple Records Using Checkbox Checked In Laravel?

@snapey thank you so much for your response.

thats the mistake i done.. after including check box it in the form

i did like this

  $data = $request->all();

  foreach ($data['purchase'] as $i => $id) {

    $purchase_details=Purchase_details::find($id);

$purchase_details->delete();

}

it worked fine ..

thank youu...

AbdulBazith left a reply on How To Delete Multiple Records Using Checkbox Checked In Laravel?

@ftiersch thank you so much for you repose..

let me try the code..

AbdulBazith started a new conversation How To Delete Multiple Records Using Checkbox Checked In Laravel?

Guys iam working with a project. i have huge records.

so i need to delete multiple records based on checkbox tick.

what i did is

my blade file

@foreach($purs as $pur)

<td><input type="checkbox" name="purchase[]" class="checkboxes" value="{{ $pur->id }}" /></td>

@endforeach


and i have a button for delete all data,


 <form action="{{ route('deleteall') }}" method="post">
                    {{ csrf_field() }}
                        <input type="hidden" name="_method" value="delete">

<button type="submit" >Delete all
</button>
</form>


my route file

Route::delete('deleteall/{id}','[email protected]')->name('deleteall');

so how can i delete the checked records.

i dont know what to write in the controller in deleteall method

 public function deleteall(Request $request)
    {

my model name is Purchase_details

how can i delete these??

}



Kindly some one help.

i referred in net, most of the videos and tutorials are based on ajax only.

but i have button and after checking the records i will click the button then those records must be deleted