hira4472

hira4472

Member Since 2 Weeks Ago

Experience Points
190
Total
Experience

4,810 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
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 1
190 XP
Apr
05
4 days ago
Activity icon

Started a new Conversation How To Get Array Of Orders And Sub Array Of Product Details In Each Array Of Orders?

First I wanted to show all orders of specific customer so I did this:


  $finaldata = array();
        $finaldata['status']="success";
        $finaldata['reason']="record fetched successfully";
        $orderdetail=orderdetail::where('OrderID',$id)->get();
        
        
        $finaldata['order']=$orderdetail;


        return response()->json($finaldata);

It is giving me this response in postman

{
    "status": "success",
    "reason": "record fetched successfully",
    "order": [
        {
            "OrderDetailID": 1,
            "OrderDate": "12-1-2020",
            "StatusID": 1,
            "ProductID": 3,
            "OrderID": 1
        },
        {
            "OrderDetailID": 2,
            "OrderDate": "12-1-2020",
            "StatusID": 1,
            "ProductID": 2,
            "OrderID": 1
        }
    ]
}

Now I don't want to display the product, its details, and status details instead of product ID, and Status ID. How would i do that?

I have also made relationship among tables.

class product extends Model
{protected $hidden = ['created_at','updated_at','remember_token'];
    public $timestamps = false;
    protected $table='products';
    protected $primaryKey ="ProductID";
    protected $fillable=["ProductName","SubCatID","YardID","SizeID","ColorID","DescriptionID","ProductPrice","Image"];

    public function yard()
    {
        return $this->hasOne(yard::class,'YardID',"YardID");
    }
    public function color()
    {
        return $this->hasOne(color::class,'ColorID',"ColorID");
    }
    public function description()
    {
        return $this->hasOne(description::class,'DescriptionID',"DescriptionID");
    }
    public function size()
    {
        return $this->hasOne(size::class,'SizeID',"SizeID");
    }

}

class orderdetail extends Model
{

    public $timestamps=false;
    protected $guarded=[];
    protected $primaryKey = 'OrderDetailID';
    protected $hidden = ['created_at','updated_at','remember_token'];

    public  function shippingdetail()
    {
        return $this->hasOne(shippingdetail::class,'OrderDetailID','OrderDetailID');
    }

    public  function statusdetail()
    {
        return $this->belongsTo(statusdetail::class,'StatusID','StatusID');
    }

    public  function order()
    {
        return $this->belongsTo(order::class,'OrderID','OrderID');
    }
    public  function product()
    {
        return $this->belongsToMany(product::class,'ProductID','ProductID');
    }
}
class statusdetail extends Model
{
    public $timestamps=false;
    protected $guarded=[];
    protected $primaryKey = 'StatusID';
    protected $hidden = ['created_at','updated_at','remember_token'];

    public  function orderdetail()
    {
        return $this->hasOne(orderdetail::class,'StatusID','StatusID');
    }
}

class order extends Model
{
    public $timestamps=false;
    protected $guarded=[];
    protected $primaryKey = 'OrderID';
    protected $hidden = ['created_at','updated_at','remember_token'];

    public  function orderdetail()
    {
        return $this->hasMany(orderdetail::class,'OrderID','OrderID');
    }

    public  function customerdetail()
    {
        return $this->belongsTo(customerdetail::class,'CustomerID','CustomerID');
    }

    public  function paymentdetail()
    {
        return $this->belongsTo(paymentdetail::class,'PaymentID','PaymentID');
    }

}
Mar
27
1 week ago
Activity icon

Started a new Conversation CRUD Operation Using Eloquent Model

I have these tables: ERD of my database

I'm making an API and I've built relationships among theses tables:

class address extends Model
{
    public $timestamps=false;
    protected $guarded=[];
    protected $primaryKey = 'addressID';
    protected $fillable = ['streetAddress','country','city','postalCode','employeeID'];



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

}


class department extends Model
{
    public $timestamps=false;

    protected $primaryKey = 'departmentID';
    protected $fillable= ['departmentName'];

    public  function role()
	{
	return $this->hasMany(role::class);
	}
    public  function employees()
    {
        return $this->hasMany(employee::class);
    }
class employee extends Model
{

    public $timestamps=false;
  //  protected $guarded=[];
    protected $primaryKey = 'employeeID';
    protected $fillable = ['firstName','lastName','email','password','phone','gender','roleID','departmentID'];


    public  function address()
	{
		return $this->hasMany(address::class);
	}

	
	public  function department()
	{
		return $this->belongsToMany(department::class);
	}

    public  function role()
    {
        return $this->belongsToMany(role::class);
    }


}
class privilege extends Model
{
    public $timestamps=false;
    protected $guarded=[];
    protected $primaryKey = 'privilegeID';
    protected $fillable = ['privilageName','roleID'];


    
    public  function statuse()
	{
		return $this->hasMany(statuse::class);
    }
    public  function role()
    {
        return $this->belongsTo(role::class);
    }
}
class role extends Model
{
    public $timestamps = false;
    protected $guarded = [];
    protected $primaryKey = 'roleID';
    protected $fillable = ['roleName','departmentID'];

    public  function privilege()
	{
	return $this->hasMany(privilege::class);
	}

    public  function employee()
    {
        return $this->hasMany(employee::class);
    }
    public  function department()
    {
        return $this->belongsTo(department::class);
    }



}

class statuse extends Model
{

    public $timestamps = false;
    protected $guarded = [];
    protected $primaryKey = 'statusID';
    protected $fillable = ['edit', 'delete', 'view','privilegeID'];

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

}

Now my role and employee tables are dependent on department table so I want that when I delete any department, it's related employees and roles should also be deleted. I don't know how to do it using eloquent model.

I've tried this in my role Controller but it's not working.

  public function destroy($id)
    {

        $roles = new role;
        $roles = $roles::find($id);
        $roles->$roles->departments()->attach(['departmentID']))->delete();
        //$roles->delete($roles->departments()->attach(['departmentID']));
        if ($roles) {
            $finaldata['status'] = "Record Deleted";
            $finaldata['reason'] = "Record Deleted Successfully";

        } else {

            $finaldata['status'] = "Record Not Deleted";
            $finaldata['reason'] = "Record was not present";

        }
        $finaldata['deleted role data '] = $roles;
        return response()->json($finaldata);

    }

}

May be I'm missing any point or logic here, kindly guide me.

Mar
25
2 weeks ago
Activity icon

Replied to When I Add Method('patch') In My View I Get Syntax Error

where are youe @error messages saved?

Mar
24
2 weeks ago
Activity icon

Replied to Why Sections And Yield And Not Include?

why don't we end section of title?

Mar
20
2 weeks ago
Activity icon

Replied to Dynamically Dependent Drop-Down Lists Without AJAX & JQUERY

I have 3 different tables in database named productdetails,categories & subcategorydetails and likewise I have 3 different Controllers ProductdetailContoller,CategoryController & SubcategorydetailController respectively. Currently, i'm working on SubcategorydetailContoller's 'view' which is subcategory.blade.php

`

            @csrf
            <div class="form-group">

              <select name="productid">


                <option value="select product">
                @foreach ($productdetail as $row)
                  <option value="{{$row->ProductID}}">
                    {{$row->ProductType}}
                  </option>
                  @endforeach
                  </option>
              </select>

              <select name="categoryid">


                <option value="select category">
                @foreach ($category as $row)
                  <option value="{{$row->CategoryID}}">
                    {{$row->CategoryType}}

                  </option>
                  @endforeach
                  </option>
              </select>

              <input type="text" name="subcategory"/>

              <input type="submit" value="add category"/>
            </div>
          </form>
        </div>`

Now, i want to make dynamically dependent drop-down lists. I got the data on second drop down using this code:

 public function index()
    {

        $productdetail=productdetail::all();
     
        $category=category::all();

            /*$category=category::where(DB::table('categories')
            ->join('productdetails','categories.ProductID','=','productdetails.ProductID')
                ->select('categories.CategoryType')
            //->whereRaw('categories.ProductID="1"')
            ->get());*/
            return view('subcategory')->with([
                'productdetail'=>$productdetail,
                'category' => $category,

        ]);


    }

Now I'm not getting where I'm doing mistake in joining and establishing logic that when I selected the specific product from first drop down then it would show only categories of that selected product on second drop down??

public function index(Request $request)
    {

        $productdetail=productdetail::all();

        $data=new productdetail();
        $data=new productdetail();
        $data->ProductID=$request->productid;
        $category=category::where(DB::table('categories')
            ->join('productdetails','categories.ProductID','=','productdetails.ProductID')
             ->select('categories.CategoryType')
            ->whereRaw('categories.ProductID='.$data.'')
            ->get());

        return view('subcategory')->with([
            'productdetail'=>$productdetail,
            'category' => $category,

        ]);


    }

The above code showing this error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"ProductID"?}' at line 1 (SQL: select categories.CategoryType from categories inner join productdetails on categories.ProductID = productdetails.ProductID where categories.ProductID={"ProductID":null})

Activity icon

Replied to Dynamically Dependent Drop-Down Lists Without AJAX & JQUERY

I'm trying to show only specific options on second drop-down depended on the selection of first drop-down

Activity icon

Started a new Conversation Dynamically Dependent Drop-Down Lists Without AJAX & JQUERY

I'm not getting where I'm doing mistake in joining and establishing logic that when I selected the specific product from first drop down then it would show only categories of that selected product on second drop down??

public function index(Request $request)
    {

        $productdetail=productdetail::all();

        $data=new productdetail();
        $data=new productdetail();
        $data->ProductID=$request->productid;
        $category=category::where(DB::table('categories')
            ->join('productdetails','categories.ProductID','=','productdetails.ProductID')
             ->select('categories.CategoryType')
            ->whereRaw('categories.ProductID='.$data.'')
            ->get());

        return view('subcategory')->with([
            'productdetail'=>$productdetail,
            'category' => $category,

        ]);


    }

The above code showing this error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"ProductID"?}' at line 1 (SQL: select categories.CategoryType from categories inner join productdetails on categories.ProductID = productdetails.ProductID where categories.ProductID={"ProductID":null})