ihprince

Member Since 1 Year Ago

Experience Points
5,680
Total
Experience

4,320 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
49
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.

  • Community Pillar

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

Level 2
5,680 XP
Feb
17
2 weeks ago
Activity icon

Replied to How To Resize Image Before Upload In Laravel?

Thanks for pointing me out

Activity icon

Replied to How To Resize Image Before Upload In Laravel?

I already tried this, It gives this error

 " Quality must range from 0 to 100. "
Activity icon

Replied to How To Resize Image Before Upload In Laravel?

It holds the requested image which comes from input file .

 $image = $request->image;
Activity icon

Started a new Conversation How To Resize Image Before Upload In Laravel?

I want to resize image beofre upload it into database. I store image in this way

$image = $request->image;

  if ($image) {
     $image_name = hexdec(uniqid());
       $ext      = strtolower($image->getClientOriginalExtension());
       $image_full_name = $image_name . '.' . $ext;
       $upload_path     = 'foods/';
       $upload_path1    = 'images/foods/';
       $image_url       = $upload_path . $image_full_name;
       $success         = $image->move($upload_path1, $image_full_name);

        }

Now, I want to resize image before uploading it. I try to use intervation package, I try this

if ($image) {
     $image_name = hexdec(uniqid());
       $ext      = strtolower($image->getClientOriginalExtension());
       $image_full_name = $image_name . '.' . $ext;
       $upload_path     = 'foods/';
       $upload_path1    = 'images/foods/';
       $image_url       = $upload_path . $image_full_name;
       $img = Image::make($image)->resize(300, 200);
       $img->save($upload_path1, 60, $image_full_name);

        }

and I got this error

 "Encoding format (1691942233153059.jpg) is not supported."

What is the best way to resize image before upload and also set image with unique name?

Feb
15
2 weeks ago
Activity icon

Started a new Conversation How To Make Custom Login Only For Admin In Laravel?

I use laravel ui for authentication. Now, I want to custom login where only the admin can log in, otherwise, the user will be redirected to the user's login page. In the user's table one column name "is_admin". If is_admin == 1 then returns to admin panel otherwise return to user's login page. Here is my custom login method

public function adminAuth(Request $request) {

    $request->validate([
        'email'    => 'required',
        'password' => 'required',
    ]);
    $credentials = $request->only('email', 'password');
    if (Auth::attempt($credentials)) {
       // what goes here?
    }
    return redirect()->back()->with('error', 'Oppes! You have entered invalid credentials');
} 

Now, How to do that what I want?

Feb
13
2 weeks ago
Activity icon

Started a new Conversation How To Update Data Only If User Changes Anything?

Update data only if the user changes anything otherwise return a message that nothing to update. After click the edit button, if the user hits update button without change anything then return message nothing to update. If the user changes anything in the edit form then it will be updated.

I tried with this

( I have multiple fields. This is for demo)
   
    if ($user->name == $request->name && $user->email == $request->email && $user->contact                                         
         == $request>contact) {
            return back()->with('info', 'You have not change anything. Nothing to update!');

        } else {
            $user->update([
                'name'    => $request->name,
                'email'   => $request->email,
                'contact' => $request->contact,
                'image'   => $image,
            ]);

        }
        return redirect()->route('admin.home')->with('success', 'Profile has been updated');

That work's fine except image.

Here is my image upload process

 if ($request->has('image')) {
     Storage::delete('public/avatar/users/' . $user->image);
      $image_name = hexdec(uniqid());
      $ext  = strtolower($request->image->getClientOriginalExtension());
      $image_full_name = $image_name . '.' . $ext;
      $request->image->storeAs('avatar/users/', $image_full_name, 'public');
      $image = $image_full_name;
        } else {
            $image = $user->image;
        }

How can I do this with image? What is the best way to do that?

Feb
05
1 month ago
Feb
04
1 month ago
Activity icon

Replied to How To Get Order Item Total Price With Quantity From Another Table?

That's a client requirement, not mine.

Feb
03
1 month ago
Activity icon

Started a new Conversation How To Get Order Item Total Price With Quantity From Another Table?

How can I get order items total price by quantity from another table using eloquent?

Order table fields:

id,

user_id,

quantity,

Order food items table fields: <--- This is pivot table

id,

order_id,

food_item_id,

food_item_price_id,

quantity,

food_item_price table fields:

id,

food_item_id,

price

Here is relation in order model

  public function orderFoodItems() {
    return $this->belongsToMany(FoodItem::class, 'order_food_items', 'order_id', 'food_item_id')
        ->withPivot('food_item_price_id', 'quantity')
        ->withTimestamps();
  }

Now, how can I get order items total price? Suppose, one user order 2 items with 3,6 quantity respectively. How to get total price of those items with quantity??

Jan
28
1 month ago
Activity icon

Replied to How To Add Multiple Array Values Into Pivot Table?

I know its wrong, It's been 4-5 hours, I try to solve it.

Activity icon

Started a new Conversation How To Add Multiple Array Values Into Pivot Table?

I want to add array data into the pivot table. there are many food item IDs in the cart,. I want that all ID will be added as array or if have any other way.

Here is table structure

      orders
          id 
		 name 
		quantity

	cart
		  id 
		 food_item_id 
		quantity

	food_items
			  id 
			  user_id 
			 price

pivot table
order_id,
food_item_id,
food_item_price_id,
quantity

Here is the model relations

 public function orderFoodItems() {
    return $this->belongsToMany(FoodItem::class, 'order_food_items', 'order_id', 'food_item_id')->withTimestamps();
}
Jan
27
1 month ago
Activity icon

Replied to How To Upload Picture When Register?

@tray2 Thank you so much. Problem has solved

Activity icon

Replied to How To Upload Picture When Register?

@automica Thanks, I forgot this one.

Also thanks @tray2 ,

Activity icon

Replied to How To Upload Picture When Register?

By doing this

dd(request()->file('image'));

I get nothing. But doing this ,

dd($data);

I get the image

"image" => "avatar.png"

Activity icon

Replied to How To Upload Picture When Register?

@tray2 I declare variable above if statement as,

$image = ' ' ;

registration is success but the image is not stored into the database.

Activity icon

Replied to How To Upload Picture When Register?

I changed this protected to public function . Right now, I got this error "Undefined variable: image"

Activity icon

Started a new Conversation How To Upload Picture When Register?

Hi, I'm trying to upload an image in laravel default user registration. I'm using laravel ui package.

Here is create method in RegisterController

protected function create(array $data) {

        if (request()->hasFile('image')) {
      	  $image = request()->file('image')->getClientOriginalName();
        	request()->file('image')->storeAs('avatars', $image, 'public');
    }
    return User::create([
        'name'     => $data['name'],
        'email'    => $data['email'],
        'address'  => $data['address'],
        'image'    => $image ,
        'contact'  => $data['contact'],
        'password' => Hash::make($data['password']),
    ]);

I'm getting this error TypeError

Argument 1 passed to App\Http\Controllers\Auth\RegisterController::create() must be an instance of Illuminate\Http\Request, array given

What is the right way to upload an image when registering?

Jan
25
1 month ago
Activity icon

Replied to How To Display Related Products Through Pivot Table?

@nimrod I want to get all food items from a specific category. Suppose a user clicks on a food item which Id is 1 and It is belongs to category ID 2. Now I want to show more food items which is in the category ID 2. I want to display that in my view blade. I hope, you understand my problem

Activity icon

Started a new Conversation How To Display Related Products Through Pivot Table?

I want to display related item which is in same category.

Here is my 3 table structure

food item table : "food_item_id",

"name" ,

"image" ,

food item category table :

"food_item_category_id"

"name"

pivot table

id,

food_item_id

food_item_category_id

Here is FooItem model

public function foodItemCategory() {

    return $this->belongsToMany(FoodItemCategory::class, 'food_items_have_categories', 'food_item_id', 'food_item_category_id')
        ->withPivot('food_item_id', 'food_item_category_id')
        ->withTimestamps();
}

Here is the food category Model

public function foodItem() {

    return $this->belongsToMany(FoodItem::class, 'food_items_have_categories', 'food_item_category_id', 'food_item_id')
        ->withPivot('food_item_id', 'food_item_category_id')
        ->withTimestamps();
}

Now, how can I display the related products in view which is in the same category?

Jan
21
1 month ago
Activity icon

Replied to How To Get Data From Another Table Through Pivot Table?

Thanks for your reply. I already tried this way but couldn't get the value.

Activity icon

Started a new Conversation How To Get Data From Another Table Through Pivot Table?

I want to display all food_item_category name in view which is belongs to food item

Here is my 3table informations

food item table column: "food_item_id", "name" , "image"

food item category table column: "food_item_category_id" , "name"

pivot table name "food_items_have_categories" and its column is

-> id,

--> food_item_id

-->food_item_category_id

Here is fooditem model

public function foodItemCategory() {

    return $this->belongsToMany(FoodItemCategory::class, 'food_items_have_categories', 'food_item_id', 'food_item_category_id')
        ->withTimestamps();
}

I am displaying food details in ajax request. Here is my controller

public function getProduct()

{

    $products = FoodItem::all();
    return response()->json($products);
}

Here is in view

    var i = 1 ;
          $.each(response, function(key, value){              
            data = data + "<tr>"
            data = data + "<td>"+i+++"</td>"
            data = data + "<td>"+ "<img src='/storage/items/food/"+value.image+"'/>"  +"</td>"
            data = data + "<td>"+value.name+"</td>"

Now, I want to display food_item category in the table. How to do that through pivot table?

Jan
17
1 month ago
Activity icon

Started a new Conversation How To Riderect User To Login Page Using Ajax

I am adding cart items into the cart via ajax. I want that when a user clicks on the add to cart button it redirects user to login page if he/she is not logged in. It redirects into xhr network section but not in view.

Here is my ajax code

$.ajaxSetup({ headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content") } });

$(document).on('submit', '#addToCart', function(event){ event.preventDefault(); var id = $(this).data('id');

$.ajax({
url:"{{url('/cart/add/')}}/"+id,
method:"POST",
data: new FormData(this),
contentType: false,
cache:false,
processData: false,
dataType:"json",

success:function(response)
{  
  if (response.success) {
    $('#message').append(
    '<div class="alert alert-success alert-dismissible shadow mb-5 fade show" role="alert">'+
          response.success+
          '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">' + '</button>'+
    '</div>'
  );
  $('.cart').html(response.cartItem);
  }

  
  console.log(response);
  

}//success end

});

});

Here is my controller code

public function AddCart(Request $request) { if (Auth::check()) { $product = Product::where('id', $request->product_id)->first(); $quantity = $request->quantity;

        $cart = Cart::updateOrCreate([
            'product_id' => $request->product_id,
            'user_id'    => auth()->user()->id,
        ],
            ['quantity'   => $quantity,

                'total_price' => $product['price'] * $quantity,
            ]);

        if (auth()->user()) {
            $user_id  = auth()->user()->id;
            $cartItem = Cart::where('user_id', $user_id)->count();

        }
     

        return response()->json(['success' => 'product added to cart', 'cartItem' => $cartItem]);

    } else {
        return redirect()->route('login');
    }
}

Can anyone tell me how to do that?

Jan
12
1 month ago
Activity icon

Replied to How To Get Total Price Of Cart Item?

It shows an error like this

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'price' in 'field list' (SQL: select sum(price) as aggregate from carts where user_id = 1)

There is no column ('price') in cart table. Price column is in Product table

Activity icon

Started a new Conversation How To Get Total Price Of Cart Item?

I have a cart table where column is "id" "user_id" "product_id" "quantity".

When a user add item into cart ,I want to get total price of his added item into cart. How to do that?

Dec
03
3 months ago
Activity icon

Replied to How To Configure Larave Mail In Heroku?

Thanks for your reply.

I add those things and I got a error like this "Failed to authenticate on SMTP server with username" . Do you know how to solve that?

Activity icon

Started a new Conversation How To Configure Larave Mail In Heroku?

I deploy my laravel app on Heroku. Everything is fine except mail. I do not know how to configure mail driver in heroku. In local, I can send email perfectly, but I do not know how to do that in heroku. Can anyone tell me the procedure?

Here is my .env

MAIL_MAILER=smtp

MAIL_HOST=smtp.googlemail.com

MAIL_PORT=465

[email protected]

MAIL_PASSWORD=123456

MAIL_ENCRYPTION=ssl

Do I have to add this in Heroku Config Vars?

Oct
23
4 months ago
Activity icon

Started a new Conversation Showing A Description Without Html Tags And Limit Chars

I am developing a Ecomerce site I am using summernote as editor and save data with html tags. In blade template I am using to show this descriptions with limit 100 chars. But shows with all html tags. like styles fonts etc. I want to show only text without html tags. How to solve this?

Here is my code

{{(Str::limit($product->description,100))}}