AbdulBazith

AbdulBazith

Member Since 1 Year Ago

Tamil Nadu, Tirunelveli

Experience Points 14,020
Experience Level 3

980 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.

20 May
3 days 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 week 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 week 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 week 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 week 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 week ago
10 May
1 week 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
2 weeks 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
2 weeks 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

01 May
3 weeks ago

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

@ftiersch @grenadecx i think need to use trigger option in my add button.

but i dont know how.

just using

  trigger('chosen:updated');

showing error

Uncaught ReferenceError: trigger is not defined

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

@grenadecx this what i have,

my drop down


 <td> <select id="product_name" class="form-control product_name" name="product_name[]" data-placeholder="Choose One"
         required>

         <option value="">Select Product</option>

         @foreach($products as $product)
         <option value='{{ $product->id }}' data-unit="{{$product->product_unit }}"
             data-cat="{{ $product->product_type->product_type }}" data-pro="{{ $product->product_name }}">

             {{$product->id }}</option>
         @endforeach
     </select>
 </td>

my add button

 <input type="button" id="aa" class="btn btn-info" onclick="insRow()" value="Add">

this is my insRow() function

function insRow()
 {

        var table = document.getElementById('purchase_table');

        var rowCount = table.rows.length;

        var row = table.insertRow(rowCount);

        var colCount = table.rows[1].cells.length;

        for (var i = 0; i < colCount; i++) 
{
            var newcell = row.insertCell(i);

            newcell.innerHTML = table.rows[1].cells[i].innerHTML;
        }

     
    }

this is my table

<table class="table table-bordered mb30" id="purchase_table">

and the below code i used. why i used this code because when i select a product from the select box, its relevant unit must be filled in the next text box for that i used.

to know more about this refer:

https://laracasts.com/discuss/channels/laravel/how-to-fetch-rate-of-a-product-from-db-which-is-selected-in-select-box-in-array


        var selected = $('option:selected', this);
      

        $(this).parent().parent().find('.unit').val(selected.data('unit'))

        $(this).parent().parent().find('.product_type').val(selected.data('cat'))

        $(this).parent().parent().find('.pro_name').val(selected.data('pro'))

    });

whats my problem is, i have the drop down in array.

its

name=product_name[]
  id=product_name 
 class=product_name

the chosen just works for first drop down only, not for second one.

i used it in my ad button code

function insRow()
 {

        var table = document.getElementById('purchase_table');

        var rowCount = table.rows.length;

        var row = table.insertRow(rowCount);

        var colCount = table.rows[1].cells.length;

        for (var i = 0; i < colCount; i++) 
{
            var newcell = row.insertCell(i);

            newcell.innerHTML = table.rows[1].cells[i].innerHTML;
        }

  $("select.product_name").chosen();

     
    }

it shows error


Uncaught TypeError: $(...).chosen is not a function
    at insRow (create:1951)
    at HTMLInputElement.onclick (create:1880)

what can i doo kindly help me please

30 Apr
3 weeks ago

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

@ftiersch i cant use id because there are many drop down based on user selection.

i tried to execute the function inside my add function but it shows error

chosen is not a function

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

@mvd thank you for you response.

i tired your code.

it shows error

array_chunk() expects parameter 1 to be array, object given 

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

@ftiersch thank you so much for you response.

but i have an array, so how can i call that again again ??

because its a purchase order list, so list may be 20 items, 30 items or more??

i have a add button to add a new row with select box??

then how it is possible???

AbdulBazith started a new conversation How To Use Search Option In Drop Down In Array Of Drop Downs Javascript

Guys i have a purchase order form with drop down filled with products, my drop downs are arrays

see

<select id="product_name" class="form-control product_name" name="product_name[]"
                                                        data-placeholder="Choose One" required>

                                                        <option value="">Select Product</option>
                                                        @foreach($products as $product)
                                                        <option value='{{ $product->id }}'
                                                            data-unit="{{$product->product_unit }}"
                                                        data-cat="{{ $product->product_type->product_type }}"
                                                            >
                                                            {{$product->product_name }}</option>
                                                        @endforeach
                                                    </select>


there are lots of product items. so i need to keep a search in the drop down

i googled and i got this solution.

to add these lines in the header

 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.min.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.jquery.min.js"></script>

and in the script section


<script type="text/javascript">

    $(".product_name").chosen();

</script>


just doing this i had search in the drop down. everything works fine.

this works only for the first drop down.

i have a add button, so that when i click that new row generates with drop downs.

but for the second drop down its not working..

what i tried is,

gave the class name of the dropdown

<script type="text/javascript">

    $("select.product_name").chosen();

</script>

but not working.

i tried

<script type="text/javascript">

    $(".product_name[]").chosen();

</script>

but this also not working.

what can i do??

some one help please.

27 Apr
3 weeks ago

AbdulBazith left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

@snapey yaa u are right snapey.

i agree with you.

as you said i need to learn about migrations.

thank you for you suggestions..

AbdulBazith started a new conversation Dividing Columns With Barryvdh/laravel-dompdf Laravel

Guys i have a small problem in my old project milkfarm

i have installed barryvdh/laravel-dompdf package for downloading it as pdf for reports like purchase, sales etc

the pdf has only 3 columns tables, so what my client expecting is to divide the page into two columns,

so pages can be reduced.

for that what can i do??

before that what i have is in my controller

 $pdf=PDF::loadView('Purchase_details.viewallpdf', [
       
            'total_amount'=>$purchase_details->sum('total'),
            'time'=>$request->search_time,
            'fromdate'=>$request->search_fromdate,          
            'total_litre'=>$purchase_details->sum('no_of_litre')

        ]);
    }

       $pdf->setPaper('A4','portrait');
        return $pdf->download('Purchase Details.pdf');

my pdf.blade file


<head>
    <style type="text/css" media="all">
        #design {
            font-family: Serif;
            border-collapse: collapse;
            width: 100%;
        }

        #design td,
        #design th,
        #design thead {
            border: 1px solid #000;
            font-size: 12px;
        }


        * {
            margin: 2px;
            padding: 2px;
        }
    </style>
</head>



<table id="design">

        <thead>
            <tr>

                <th>Date</th>
                <th>Time</th>
                <th>R/L</th>
                <th>No.of.Lit(Lt)</th>
                <th>Total(Rs)</th>
                <th>Note</th>
            </tr>
        </thead>

        <tbody>
            @foreach($purs as $pur)
            <tr>

                <td>{{ $pur->date->format('d-m-y') }}</td>
                <td>{{ $pur->time }}</td>
                <td>{{ $pur->rate_per_litre }}</td>
                <td align="right">{{ $pur->no_of_litre }}</td>
                <td align="right">{{ $pur->total }}</td>
                <td>{{ $pur->note }}</td>
            </tr>
            @endforeach
          
        </tbody>
    </table>

this generates an output pdf as like this: https://imgur.com/uwHualg

in the above image, it has only 6 columns th. so what my client expecting is to reduce the table and need to print its continuation side itself.

i removed the width: 100%; in the tag style

so what happened is,

see this image: https://imgur.com/OLrRWFT

in the above image now it is reduced. the continuation of the table must be side to next column, the page must be dived into two columns.

Kindly some one help..

in a single page two columns with continuation data...

AbdulBazith left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

@snapey thank you so much for your response.

ya i understood that changing in the single file and if i migrate it it works.

Start hacking away with phpmysql and you will soon forget all the changes you made and will be unable to reliably perform the same on production.

this you are saying that changing in sql cannot be remembered for future so there i will face problems thats what u are trying to say??

You also then have database state that is not in your code repo and cannot be rebuilt by someone else. whats this meaning???

AbdulBazith left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

@mkbat thank you so much for your response.

as i said i tried the sql commands it was some what easy.

but thank you so much for your response

22 Apr
1 month ago

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@jlrdw thank you soo much for you suggestion. thank you..

you are right, i made it harder by thinking and thinking overthinking.

any how as u said i need to first sketch it in pencil and then only i should plan.

this is so urge and i wasted few days . thats why in hurry bury, i did this.

but with @snapey suggestion i got the point and i done with few changes.

and u gave a good suggestion to follow.

what i did i mentioned in the above comment. plz u can check and u can suggest me your ideas

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@snapey

i changed the code to

&& Auth::user()->user_type == "accountant" && Auth::user()->hotels()->hotel_reg_id == $request->hotel_id)

it didnt help.

now what i did is

just changed the user table with columns

id
user_name
hotel_id (fk->hotel_registration table)
user_type
user_phno
password

and this is my hotel_registration table

id
hotel_name
hotel_location
phno

because using pivot table confusing me lot thats why. sorry for not following ur idea because u gave that must explanation.

so in login form i have a selectbox with hotel choosing, username, password. if these three are correct the it will allow to login.

and when storing data what i did is

 $purchase_order->hotel_id =Auth::user()->hotel_id;
 $purchase_order->login_user_id =auth()->id();

this stores the hotel id and user id in the purchase_order table.

so i followed the same procedure in all tables just added extra column hotel_id with foreign key and changed the controller.

to retrieve the data based on the hotel what is did is

  $suppliers = Supplier::where ('hotel_id',Auth::user()->hotel_id)->orderBy('created_at','asc')->paginate(10);

this worked for mee.

what i decided is the hotel is small concern, so if a hotel has multi user, then for each of them i will provide a username and password registered with respective hotel.

so here i just followed one to many relationship.

Thank you for your kind suggestion and help .

without any hesitation u guided me a lot

after processing if i have any doubt i will ask.

AbdulBazith left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

@snapey sorry i forgot the migration syntax in tension.

i tried

php artisan make:migration add-hotel-to-tables --table=products

and changed to

 $table->integer('hotel_id')->unsigned()->after('id')->nullable();
            $table->foreign('hotel_id')->references('id')->on('hotel_registrations');

php artisan migrate worked correctly

but in the same migration file if i just change the table name and do php artisan migrate then it says nothing to migrate.

so i followed sql commands


//this is for users table

ALTER TABLE `users`
    ADD COLUMN `hotel_id` INT(10) unsigned AFTER `user_name`;


ALTER TABLE `users`
  ADD KEY `users_hotel_id_foreign` (`hotel_id`);



ALTER TABLE `users`
  ADD CONSTRAINT `users_hotel_id_foreign` FOREIGN KEY (`hotel_id`) REFERENCES `hotel_registrations` (`id`);



just i made duplication of this code and changed the table name and foreign key name thats it.

for all tables the column with primary key is added.

but really u gave much more explanation thank you thank youuu soooo much..

and for If you have 26 tables though, with data you cannot lose, I have not a clue how you will populate these tables with the hotel_id value?

for this answer is

i will do

where ('hotel_id',Auth::user()->hotel_id)

so based on this the records are fetched.

Kindly refer this link: https://laracasts.com/discuss/channels/laravel/guys-need-a-big-suggestion-for-login-permission-for-different-users-laravel

for my changes plz

AbdulBazith left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

@safemood

the idea is tooo big. i just made sql commands i did it.


ALTER TABLE `users`
    ADD COLUMN `hotel_id` INT(10) unsigned AFTER `user_name`;


ALTER TABLE `users`
  ADD KEY `users_hotel_id_foreign` (`hotel_id`);



ALTER TABLE `users`
  ADD CONSTRAINT `users_hotel_id_foreign` FOREIGN KEY (`hotel_id`) REFERENCES `hotel_registrations` (`id`);


it succesfully done

AbdulBazith left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

@yezawhein thank you so much for your response.

i tried ur method by following through net, but i face problem. violation error, add or update foreign key

like this it showed error.

AbdulBazith left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

@snapey thank you so much for you response.

i used ur code

php artisan make:migration --table=products

it showed error

Not enough arguments (missing: "name").

actually i need to add the hotel_id for all my tables. product_category is just for example i mentioned.

to add a extra column with foreign key constrain in al tables in local and in server without deleting data? how it is possible???

AbdulBazith left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

@nakov @safemood thank you soo much for you responses.

but if i follow you methods, my data will be erased.

i need the data in it.

and being open, i need to add the column for all the tables.

just for example i have given product_category_id.

but truely, i need to add hotel_id column with foreign key in all my 26 tables.

link: https://laracasts.com/discuss/channels/laravel/guys-need-a-big-suggestion-for-login-permission-for-different-users-laravel

for the above reason only i asked

if i change it locally then how can i do the same change in server without data erased??

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@snapey

i need to do the login process manually so only i used this.

kindly suggest a solution for the coding, i was not familiar with auth functionality so only i am trying manually. for my last two projects i did like that only..

21 Apr
1 month ago

AbdulBazith started a new conversation How To Add A Foreign Key To A Table After Migration Done Laravel

Guys i have doubt.

i have a table with 4 columns.

think that, i have a table product with 4 columns product_name, rate, min quantity, date

i have migrated the table so the table is created in phpmyadmin.

but i forget to add product_category_id column in the product table with foreign key.

now how can i add a column product_category_id with foreign key constrain in product table

Kindly some one suggest pelase

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@snapey i tried these but there is problem in login

i have three tables

table: users with columns

id
user_name,
user_type
user_phno,
password


this is my hotel_registrations table with columns

id
hotel_name,
hotel_location,
phno

this is my hotel_users table with columns

id
hotel_reg_id,
users_id

and this is my User Model

 public function hotels()
    {
        return $this->belongsToMany('App\HotelRegistration', 'hotel_users','users_id','hotel_reg_id');
    }


and this is my HotelRegistrationmodel

 public function users()
    {
        return $this->belongsToMany('App\User', 'hotel_users','hotel_reg_id','users_id');
    }

and i have a login form with a select box to choose hotel name, and username, and password

<select id="hotel_id" name="hotel_id" class="form-control" style="display: block;">
                            <option value="">Choose Hotel Name</option>
                            @foreach($hotels as $hotels)
                            <option value='{{ $hotels->id }}'>{{$hotels->hotel_name
                                                }}</option>

                            @endforeach

                        </select>


 <input type="text" class="form-control" placeholder="Username" id="user_name" name="user_name">



 <input type="password" class="form-control" placeholder="Password" id="password"
                            name="password">


now how i can login with a check

i tried this but it not works

public function login(Request $request)
 {

  if (auth()->attempt(request(['user_name', 'password'])) == true && Auth::user()->user_type == "accountant" && Auth::user()->hotels() == $request->hotel_id)

 {

    dd("Login");
}

else
{
dd("error in login);
}

}

please suggest me a idea to login please...

how iam trying to login is, the user name and password should match and also the respective registered hotel for that user should also match the it should login

Kindly please reply for this

19 Apr
1 month ago

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@snapey .. u thank you thank you snapey...

immediately i will try these and i will ask if any doubts

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@snapey thank you than youuu..

i understood clearly..

hotel is one table, users is another table. hotel_user is a pivot table to relate them

that is many to many relationship. am i right.

so the pivot table will have these columns am i right???

id
hotel_id
users_id


so one hotel can have multiple user, one user can have multiple hotel

ya i understood..

is this right??

am i understood correctly??

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@snapey i think if i need to go with hotel_user table, then i need to move with multiple auth()

am i right??

but now i no need for multiple auth()

so i will better go with users table itself.

one doubt for idea, i think u understood who are my users. and what are my hotels.

for this is single auth() is enough??

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@snapey thank you.

ss in your earlier reply u said we can create new table hotel_users

but will auth() works with that table?

can i use login procedure with auth()??

thats the big doubt for mee..

because, when iam working with my job portal site i faced the same problem for authenticating user in another table.

even u have replied for that to use only users table please visit this

https://laracasts.com/discuss/channels/laravel/manual-authentication-process-with-user-defined-table-in-laravel

in this link u have said that better to use users table for all users.

so can i use users table for my users for hotel.

if i change the table what problem i will face. i think the auth will not work..

Kindly reply for this please

17 Apr
1 month ago

AbdulBazith left a reply on Guys Need A Big Suggestion For Login Permission For Different Users Laravel

@snapey

I have a doubt.

now i have created a hotel_registrations table with columns

id
hotel_name
hotel_location
phno
password
rememberToken
timestamps();

Everthing is fine

now i need to create user for each hotel. for that i can use users table?? or can i create a new table hotel_users??

why iam asking this because

if i create ```hotel_users```` table then can i use the below lines for login.

if (auth()->attempt(request(['hotel_name', 'password'])) == true && Auth::hotel_users()->type == "user")

will these lines allow me to login. or else it shows error.

my next doubt. if i created a user means

when a user put purchase order

will these lines work auth()->id(); to store the user id.

why iam asking this because allthe auth() works for table users but will it work for hotel_users table??

Kindly reply for this please

AbdulBazith left a reply on Extension For Php To Align The Controllers File In Laravel?

@nakov thank you so much for you response.

it worked. but i have already installed this.

i dont know why this not worked for me these much days.

i think my usage is wrong

any how thank you..

16 Apr
1 month ago

AbdulBazith left a reply on How To Get Total Based On Income_type Group With Different Id.

@mungpara thank you for your response.

sorry stuck in some other problem with authentication.

after clearing that insha allah surely i will try and i will inform u