danimohamadnejad

danimohamadnejad

Member Since 7 Months Ago

Experience Points
2,130
Total
Experience

2,870 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-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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
2,130 XP
Oct
20
20 hours ago
Activity icon

Started a new Conversation Authorize Controller Method Without Any Model?

Hello. I have two methods in SettingsController named settings and updateSettings. I want only authenticated admin to access these methods and no other type of user. So I want to use a policy named SettingPolicy but problem is that I am storing settings in conig > settings.php file and dont have a model for it. what class should I pair this policy with in $policies array of AuthServiceProvider so that I can use: $this->autorize('updateSettings',Type::class); in controller??

Oct
19
1 day ago
Activity icon

Started a new Conversation One Query To Get List Of Data And Total Count And Total Sum?

hello I have following table: products id name price sold_count how can I paginate through products and to get list of data along with total sold_count of all products and also total number of products, all in one query? Product::withSum('sold_count')->withCount()->paginate(); thank you in advance

Oct
18
2 days ago
Activity icon

Started a new Conversation Best Way To Add Messages To A Request?

hello. In my ecommerce application I want the users to be able to add coupon codes and get some discount. I am using a form for recieving coupon code from user in form of a POST request. if every thing is okay and coupon code exists user may get discount but there are situations in which coupon code may not exist or use has already used it or it has reache maximum usage count or user cart order total can not meet minimum amount to allow him for using coupon. as you see there may be multiple messages that I may want to return to user to be displayed. what is a good reusable way or a design pattern which can help me add these messages to each other without using lots of If and else if statements? thank you in advance

Activity icon

Started a new Conversation How To First Row With Loweset Value Of A Column?

Hello I would like to find first row from following table which has lowest sold_count:

products
id name sold_count
1  p1   20
2  p2   100
3  p3   20
4  p4   50

how can I do it using eloquent or query builder? thank you in advance

Oct
15
5 days ago
Activity icon

Replied to Auth::check() Is Not Working In Controller.php File

thank you very much this one worked

Activity icon

Replied to Auth::check() Is Not Working In Controller.php File

//I want to load all personalized recommendations if user is logged
//user currently is logged but application Auth::check() returns false
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\Components\Shop\Cart;
use App\Components\Shop\Wish;
use App\Components\RS;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    
    public function __construct(){
       $this->shareHeaderCategories();
       $this->shareCart();
       $this->shareWish();
       $this->sharePersonalizedRecommendations(); 
    }   

    public function sharePersonalizedRecommendations(){
        if(\Auth::check()){
         $recommendations=RS::getPersonalizedRecommendations();
         var_dump($recommendations);exit;
        }
    }
    
    public function shareHeaderCategories(){
        $crepo=resolve('App\Repos\CategoryRepo');
        $headerCategories=$crepo->getHeaderCategories();
        view()->share('headerCategories',$headerCategories);
    }
    public function shareWish(){
        $wish=Wish::get();
        view()->share('header_wish',$wish);
    }
    public function shareCart(){
        $cart=Cart::get(false);
        view()->share('header_cart',$cart);
    }

}
Activity icon

Replied to Auth::check() Is Not Working In Controller.php File

unfortnately inside app service provider I cannot check login. it still returns false

Activity icon

Replied to Auth::check() Is Not Working In Controller.php File

thank very much for your answer

Activity icon

Replied to Auth::check() Is Not Working In Controller.php File

<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\Components\Shop\Cart;
use App\Components\Shop\Wish;
use App\Components\RS;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    
    public function __construct(){
       $this->shareHeaderCategories();
       $this->shareCart();
       $this->shareWish();
       $this->sharePersonalizedRecommendations(); 
    }   

    public function sharePersonalizedRecommendations(){
        if(\Auth::check()){
         $recommendations=RS::getPersonalizedRecommendations();
         var_dump($recommendations);exit;
        }
    }
    
    public function shareHeaderCategories(){
        $crepo=resolve('App\Repos\CategoryRepo');
        $headerCategories=$crepo->getHeaderCategories();
        view()->share('headerCategories',$headerCategories);
    }
    public function shareWish(){
        $wish=Wish::get();
        view()->share('header_wish',$wish);
    }
    public function shareCart(){
        $cart=Cart::get(false);
        view()->share('header_cart',$cart);
    }

}
Activity icon

Replied to Auth::check() Is Not Working In Controller.php File

I am sorry I copy and paste code but it disapears!

Activity icon

Replied to Auth::check() Is Not Working In Controller.php File

I did but still not working

Activity icon

Started a new Conversation Auth::check() Is Not Working In Controller.php File

hello. I have logged in application so Auth::check() on all controllers works. but when I use it in Controller.php file, it returns false. I am very confused please help. thank you advance.

Oct
14
6 days ago
Activity icon

Replied to Mysql Multiple Update?

thank you for reply , I am going to make a bulk update so I will use alot of those when conditions. why is it updating james when I have not included its id in condition? is there any way to solve?

Activity icon

Started a new Conversation Mysql Multiple Update?

hello. I have a table named "names" that looks like below:

id name 1 alex 2 james

I am using following command to change alex's name:

update names set name=(case when id=1 'michael' end);

above command updates alex's name but also nullifies james. please help. thank you

Oct
12
1 week ago
Activity icon

Started a new Conversation WithSum On A Column Similar To WithCount!

hello please consider following tables: products==>> id name, reviews==>id score productId

I want to get a list of proudcts along with total number of reviews and also sum of ratings for that product. something like below:

Product::withCount('reviews')->withSum('rating')->get();

how can I query such a thing? is it possible? thank you in advance.

Activity icon

Replied to How To Join To Tables With Suppressing ID Collision?

is there any way to select only afew columns from reviews and not all?

Activity icon

Started a new Conversation How To Join To Tables With Suppressing ID Collision?

hello please consider following:

Product::join('reviews','products.id','=','reviews.productsId')->groupBy('reviews.productId')->order('DB::raw('avg(rating)'));

using aboe query, I would like to sort products based on average rating but problem is that name of ID column of both products and reviews table is "id". so if I loop products using foreach, $product->id return ID of a review. please help. thank you

Oct
10
1 week ago
Activity icon

Started a new Conversation Which Route Should I Send Request To Get Some Statistics Data?

hello. following url gives me a list of paginated list of users who have registered at most 30 days ago:

/users?passed_days=30

in some points of application I may send a request with same passed_days query string parameter, but instead of getting a view I may want to get total number of registered users in this time period. where should I send such request. I mean what should my url be? thank you in advance

Oct
09
1 week ago
Activity icon

Replied to Total Count And Recent Data In One Query?

honestly I dont have any code I am just figuring out how to write it. I dont want to get any relation data are toataly separate.

Activity icon

Replied to Total Count And Recent Data In One Query?

thank you for reply. In statistics page of my application I want to have a list of recent users and also I want to show total number of users. there are others things too like total number of orders and recent orders. you know general information. Im trying to reduce number of queries since I want to display data from multiple tables.

Activity icon

Started a new Conversation Total Count And Recent Data In One Query?

Hello. how can I get recent models and also total number of rows using same query? is that possible? thank you in advance

Activity icon

Replied to Should I Query To Database For All Different Data On Same Request?

I think I should do the same using some data first and for remaining queries I will use promises. user should be able to see all data. but I think its no problem if show latest usersa and best sellings a little later than orders summary and chart. thank you

Activity icon

Replied to Should I Query To Database For All Different Data On Same Request?

yeah thank you. honestly my big worry is that if these kind of requesting all types of essential information is not correct and maybe damages database so I some times think I better request data from inside the view in form of multiple ajax request. what is your opinion about this? can it be good option?

Activity icon

Started a new Conversation Should I Query To Database For All Different Data On Same Request?

hello. I want to show types of data in statistics page of website. for instance I want to show a list of latest orders, summary or all orders including total sales, groups sales based on monthes, new users, best selling products and maybe event some other sort of information. my quistion is that is it okay to query them all in my controller method and sent them to view? because I feel these may be to many queries? please guide.

Oct
08
1 week ago
Activity icon

Replied to How To Update All Rows Using One Query?

this is okay but I think we are writing more than once, right?

Activity icon

Started a new Conversation How To Update All Rows Using One Query?

Hello. please consider following data: $data=[ ['id'=>'1','stock'=>'12'], ['id'=>'2','stock'=>'13'] ]; how can I update all stocks using IDs using one query?

Activity icon

Replied to Session Variable Is Not Updating In Ajax Request

now its working I just dont know what the problem was

Activity icon

Replied to Session Variable Is Not Updating In Ajax Request

please consider follwing form:

I send above form using ajax request. I also can verify that all data reaches server. I just do following:

session(['cart_product'=>$data['productId']]);

session(['cart_quantity'=>$data['quantity']]);

above session variables simply set when I send form using traditional http because I can get them in another page. but ajax request doesnt set them.

Activity icon

Started a new Conversation Session Variable Is Not Updating In Ajax Request

hello. in product details page I have a form by which I can add the product to cart through ajax. cart date are stored in a session variable . ajax request looks not updating session variable. I tested using ordinary http request and redirected to another route after setting session variable and everything is okay. however ajax request cannot update session variable. please help

Oct
07
1 week ago
Activity icon

Replied to How To Update Many Rows Using IDs?

yes its true. can I do that using eloquent to build that query??

Activity icon

Started a new Conversation How To Update Many Rows Using IDs?

hello. In ecommerce application I want to reduce stock column of products in the cart after order is set. I have a list of product IDs and also qunatity of each one in the cart. so I have an array of Id-quantity pairs: [ ['1','20'], ['2','15'], ... ]

how should I update all products using one query?

Activity icon

Replied to How To Forbid User From Model Specific Property?

ohhhh thanks. how can I use this method using Validator::make()?

Activity icon

Replied to How To Forbid User From Model Specific Property?

are you using above solution user cannot update stateId property? because I am using mass assignment and I feel user can change form and add stateId .

Activity icon

Started a new Conversation How To Forbid User From Model Specific Property?

hello. in my ecommerce application I want both user and admin to be able to update an Order model. user should update its order model all properties except to "stateId" and admin should only be able to update "stateId" of every order model. now I want both roles use the same PUT route for updating. what is best practice? thank you in advance

Oct
05
2 weeks ago
Activity icon

Started a new Conversation Updating A Single Property Of A Model

hello, there is situation I want to update "active" property of a model in controller method. following is the url: /products/2/update. validator inside controller method which handles this request also checks for title and other properties. what is the best way to bypass this validator? should I use another url?

Activity icon

Replied to Applying Copuons To Cart?

I cant use only one discounts table because there are different types and in my opinion they cannot be Distinguished with a type column. for instance I may have product based discounts so there can be a one to many relation between this table and products. Or I may have shipping based discounts or volumn based discounts which may have some differences in table columns. that's why I have a Discount Model from which different types may be extended. then using polymorphism we can implement each model algorythm to affect ShoppingCart object.

Activity icon

Started a new Conversation Applying Copuons To Cart?

hello. please give me some help on this quistion. I have a model named Discount. I also have three models which extend it including: ProductDiscount, VolumeDiscount, ShippingDiscount each one with its own table. the tables have but one column named discount_code. now consider a situation the user can send a form which contains an input named discount_code and the request is sent to DiscountController. discount model related to discount code may be in any of these tables or in none. what is the best and fastest way to find the specific discount in all these tables? thank you

Oct
04
2 weeks ago
Activity icon

Started a new Conversation How To Know If Request Is Coming From Current Website?

hello I want my controller method to accept only internal requests which are result of clicking of a anchor tag inside the website. how can I detect the request is not coming from outside?

Sep
26
3 weeks ago
Activity icon

Replied to How To Set Similar Items In Ecommerce?

this is good solution. each product has many categories so I can easily get leaf category to get similar products. do you have any Idea to help me make the criteria more accurate like those whereHas which you have proposed. what should criteria be like? should I specify if the filter should be displayed in similar items when I am creating new filter???

Activity icon

Replied to How To Set Similar Items In Ecommerce?

interesting but I got confused. following is my data base:

products -->> id name

categories -->> id name parent_category_id

product_categories_pivot -->id productId categoryId

filters -->> id name

filter_options -->> id filterId value

product_options --->> id productId filterOptionId

now please guide more specifically in getting list of comparable products to a specific product.

thank you

Activity icon

Replied to How To Set Similar Items In Ecommerce?

honestly I dont have much information. I want a list of similar products to be displayed in comparison section of product details page. I need some general help in how to database should change and if I need any new table? or they are aquired on the fly?

Activity icon

Started a new Conversation How To Set Similar Items In Ecommerce?

hello every one. how should I specify similar items of a product in ecommerce website?

Sep
20
1 month ago
Activity icon

Started a new Conversation How To Round A Float To Nearest Half Or Whole?

Hello in my ecommerce application I need to display stars based on average rating so average rating may be 0, 0.5, 1,1.5.....5 I want to round float rating averages to the nearest half or whole number: 0.32 ---->> 0 0.45 ---->>0.5 1.92 ----->2 1.65------>1.5

any offer? please help thank you

Sep
19
1 month ago
Activity icon

Replied to How To Print A Category Parents Recursively?

thank you for reply I already have loaded all information I need to display hierarchy. I have implemented something which looks okay to me but it doesnt work very good and doesnt print any thing. its strange please check following code:

function printCategoryHierarchy($category,$categories){

         foreach($categories as $c){

           

            if($c->category_id==$category->category_id){

             echo $c->category_name."<br/>";

             return true;   

            }else{

             $subs=$categories->filter(function($categ) use($c){

                return $categ->category_parent_id==$c->category_id;

             });

             if($subs->count()){

              if(printCategoryHierarchy($category,$subs)){

                echo $c->category_name."<br/>";

                return true;

              }

              return false;

             }

             return false;

            }

         }

     }

     printCategoryHierarchy($category,$categories->filter(function($c) use ($category){

        return $c->category_id!=$category->category_id;

     }));

$category is desktop for instance and $categories is all categories including electronics, computers,laptops,desktops and tablets. I think you may guess hierarchy