ethar

ethar

Member Since 8 Months Ago

Experience Points
6,700
Total
Experience

3,300 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
58
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 2
6,700 XP
Aug
05
4 days ago
Activity icon

Replied to HasOneThrough RelationShip

i used this and worked successfully, but i dont know if this way cause loading in database


        $orders=Orders::select('id','products_id','users_id','addresses_id','price','status')
            ->with('users:id,fname,lname,telno')
            ->with('products:id,name_ar,img')
            ->with(['address'=>function($q){
                $q->select('id','cities_id','address')->with('city:id,city_name_ar,price');
            }])
            ->paginate(20);
Activity icon

Replied to HasOneThrough RelationShip

its not working

model function

    public function city(){
        return $this->hasManyThrough(
            'App\City',
            'App\Address'
        );
    }

controller function

    public function index()
    {
        $orders=Orders::select('id','products_id','users_id','addresses_id','price','status')
            ->with('users:id,fname,lname,telno')
            ->with('products:id,name_ar,img')
            ->with('address:id,cities_id,address')
            ->with('city:id,city_name_ar,price')
            ->paginate(20);
        return view('admin.orders.indexorder',compact('orders'));
    }
Activity icon

Replied to HasOneThrough RelationShip

its not working,

sql error

 inner join `addresses` on `addresses`.`id` = `cities`.`addresses_id` 

but must be

inner join `addresses` on `addresses`.`cities_id` = `cities`.`id`
Activity icon

Started a new Conversation HasOneThrough RelationShip

i have City Model (id,name),

and

Address Model (id,cities_id,users_id)

and

Orders Model (id,products_id,addresses_id).

in Orders Model i wrote this function to get city Name

    public function cities(){
        return $this->hasOneThrough(
            'App\City',
            'App\Address',
            'cities_id',
            'addresses_id',
            'id',
            'id'
        );
    }

but i got this error

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous (SQL: select `id`, `city_name_ar`, `price`, `addresses`.`cities_id` as `laravel_through_key` from `cities` inner join `addresses` on `addresses`.`id` = `cities`.`addresses_id` where `addresses`.`cities_id` in (1, 2, 3, 4))
Aug
03
6 days ago
Activity icon

Replied to Move Calculation To Model Instead Of Blade

@sinnbeck thanks but i replaced $product with $this, thanks working successfully.

Activity icon

Started a new Conversation Move Calculation To Model Instead Of Blade

I have product price, first I check if the deal exists will discount deal discount from product price, then check if a discount exists will apply the discount.

this work successfully, but I do this in blade file, any way to write this in model

@if($product->coupouns)
    {{number_format($product->price -( $product->price * $product->coupouns->discount / 100)) }}
@elseif($product->discount)
    {{number_format($product->price -( $product->price * $product->discount / 100)) }}
@else
    {{$product->price}}
@endif
Aug
02
1 week ago
Activity icon

Started a new Conversation Send Static Data With Eloquent Result

from cookies, I get (item_id, item_qty), depend on item_id I make a select statement to return data,

I want to send item_qty with this statement to the blade

if(isset($_COOKIE["shopping_cart_panorama"])){
    $cookie_data = stripslashes($_COOKIE["shopping_cart_panorama"]);
    $cart_data=json_decode($cookie_data,true);
    $products=[];
    $qty=[];
    foreach ($cart_data as $key=>$values){
        array_push($products,$values['item_id']);
        array_push($qty,$values['item_qty']);//how send quantity with query result
    }
    $cart_product=Products::select('id','img', productName','price')
        ->whereIn('id',$products)
        ->where('active',1)
        ->get();
}
return view('front.cart',compact('cart_product'));

in the blade, I wat to show data get from the eloquent query, with the quantity of each product that comes from cookies

Activity icon

Started a new Conversation Query Inside Foreach

i try to get all product where id in array

 if(isset($_COOKIE["shopping_cart_panorama"])){
   $cookie_data = stripslashes($_COOKIE["shopping_cart_panorama"]);
   $cart_data=json_decode($cookie_data,true);
   $products=[];
   foreach ($cart_data as $key=>$values){
       $products=Products::select('id','img','slug_'.getLange().' as slug','name_'.getLange().' as productName','price')
                    ->where('active',1)
                    ->where('id',$values['item_id'])
                    ->take(5)
                    ->get();
            }
  return $products;
        }

but its return just first result (id)

Activity icon

Replied to Cookies In Laravel

{message: "Call to undefined function App\Http\Controllers\collec()", exception: "Error",…} exception: "Error" file: "C:\xampp\htdocs\site\panorama\app\Http\Controllers\HomeController.php" line: 106 message: "Call to undefined function App\Http\Controllers\collec()"

Activity icon

Started a new Conversation Cookies In Laravel

hi, I'm PHP developer, but newbie in Laravel, I used this code (Pure PHP), to store products in cookies,

if cookies not exist, will create it and store product_id, qty.
if cookies exist, will add product_id, qty to cookies.
if cookies exist and product_id exist, will update qty.

I want to ask if in laravel can improve or simplify this code

    public function addToCart($pid,$qty){
        if(isset($_COOKIE["shopping_cart_panorama"])){
            $cookie_data=stripslashes($_COOKIE["shopping_cart_panorama"]);
            $cart_data=json_decode($cookie_data,true);
        }else{
            $cart_data = array();
        }
        $item_id_list=array_column($cart_data,'item_id');
        if(in_array($pid,$item_id_list)){
            foreach ($cart_data as $keys => $values){
                if($cart_data[$keys]["item_id"] == $pid){
                    $cart_data[$keys]["item_qty"] = $cart_data[$keys]["item_qty"] + $qty;
                }
            }
        }else{
            $item_array = array(
                'item_id' => $pid,
                'item_qty' =>$qty,
            );
            $cart_data[] = $item_array;
        }
        $item_data = json_encode($cart_data);
        $setCookies = @setcookie('shopping_cart_panorama', $item_data, time() + (3600 * 24 * 30),"/");
    }
Jul
29
1 week ago
Activity icon

Started a new Conversation Update Existing Cookies

hi when user add the item to cookies its add successfully but when add another item its deleted old cookies and add just new item how to add the item to existing cookies

Cookie::queue(Cookie::make('product', $pid . "," . $qty, 3600));
Activity icon

Started a new Conversation Save Multi Value In Cookies

hi i want to store product_id, quentity to Cookies, but not work public function addToCart($pid,$qty){ $data = [ ['pid'=>$pid, 'qty'=> $qty], ]; Cookie::queue(Cookie::make('product',$pid,3600)); }

and how check if pid is already exist

Activity icon

Started a new Conversation Missing Required Parameters (Ajax , Laravel)

hi I used ajax to add the item to cart, but I got an error (Missing Parameter) any help

ajax code

        $('#button-cart').on('click', function () {
            var productId= $("#product_id").val();
            var qty= $("#input-quantity").val();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': "{{ csrf_token() }}"
                },
                type:'get',
                data : { productId : productId, qty : qty },
                url:'{{ route('addtocard') }}',
                beforeSend: function () {
                    $('#button-cart').button('loading');
                },
                complete: function () {
                    $('#button-cart').button('reset');
                },
            })
        });

route file

Route::get('/addtocart/{productId}/{qty}', '[email protected]')->name('addtocard');
Jul
26
2 weeks ago
Activity icon

Replied to Virtual Host In Xampp Redirect To Same Url

thanks @marianomoreyra for your reply but still not working

httpd-vhosts.conf file

# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin [email protected]
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin [email protected]
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/hebron/public"
    ServerName hebron
    ServerAlias *.hebron.test
    <Directory "C:/xampp/htdocs/site/hebron/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/blog/public"
    ServerName blog
    ServerAlias *.blog.test
    <Directory "C:/xampp/htdocs/site/blog/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

hosts file

# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
127.0.0.1           localhost
#::1                 localhost
127.0.0.1			 hebron.test
127.0.0.1			 blog.test
Jul
25
2 weeks ago
Activity icon

Started a new Conversation Virtual Host In Xampp Redirect To Same Url

I used Laravel, Xampp in windows 10 I created a virtual host

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/hebron/public"
    Servername hebron
    ServerAlias www.hebron.test
    <Directory "C:/xampp/htdocs/site/hebron/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

in hosts file

127.0.0.1	hebron.test 

until now it's working perfectly, but when creating another one

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/site/blog/public"
    Servername blog
    ServerAlias www.blog.test
    <Directory "C:/xampp/htdocs/site/blog/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

in hosts file

127.0.0.1 blog.test

the problem when visit blog.test , or hebron.test its redirect to same (hebron.test)

Jul
23
2 weeks ago
Activity icon

Replied to Hello All

Hellow and welcome

Activity icon

Started a new Conversation Check Url Have Specific Parameter

plz how to check if URL has a parameter e.x http://panorama.test/en/cat or http://panorama.test/en/cat/1/data

I use optional id (1), slug(data), I want to check if id or slug exists in URL or not. how in controller make eloquent to get all data if id or slug not exist, how to get data related to id if id sent.

Jul
21
2 weeks ago
Activity icon

Replied to Mcamara Package Error

when i perform any of above commands I got

Mcamara\LaravelLocalization\Exceptions\SupportedLocalesNotDefined

Supported locales must be defined.

at C:\xampp\htdocs\site\panorama\vendor\mcamara\laravel-localization\src\Mcamara\LaravelLocalization\LaravelLocalization.php:470 466| 467| $locales = $this->configRepository->get('laravellocalization.supportedLocales'); 468| 469| if (empty($locales) || !\is_array($locales)) {

470| throw new SupportedLocalesNotDefined(); 471| } 472| 473| $this->supportedLocales = $locales; 474|

1 C:\xampp\htdocs\site\panorama\vendor\mcamara\laravel-localization\src\Mcamara\LaravelLocalization\LaravelLocalization.php:141 Mcamara\LaravelLocalization\LaravelLocalization::getSupportedLocales()

2 C:\xampp\htdocs\site\panorama\vendor\mcamara\laravel-localization\src\Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider.php:55 Mcamara\LaravelLocalization\LaravelLocalization::__construct()

Activity icon

Replied to Mcamara Package Error

when i perform any of above commands I got

Mcamara\LaravelLocalization\Exceptions\SupportedLocalesNotDefined

Supported locales must be defined.

at C:\xampp\htdocs\site\panorama\vendor\mcamara\laravel-localization\src\Mcamara\LaravelLocalization\LaravelLocalization.php:470 466| 467| $locales = $this->configRepository->get('laravellocalization.supportedLocales'); 468| 469| if (empty($locales) || !\is_array($locales)) {

470| throw new SupportedLocalesNotDefined(); 471| } 472| 473| $this->supportedLocales = $locales; 474|

1 C:\xampp\htdocs\site\panorama\vendor\mcamara\laravel-localization\src\Mcamara\LaravelLocalization\LaravelLocalization.php:141 Mcamara\LaravelLocalization\LaravelLocalization::getSupportedLocales()

2 C:\xampp\htdocs\site\panorama\vendor\mcamara\laravel-localization\src\Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider.php:55 Mcamara\LaravelLocalization\LaravelLocalization::__construct()

Activity icon

Started a new Conversation Mcamara Package Error

hi after install Mcamara Package i got this Error Mcamara\LaravelLocalization\Exceptions\SupportedLocalesNotDefined Supported locales must be defined.

any solution to solve this problem

Jul
20
2 weeks ago
Activity icon

Started a new Conversation Eloquent Error When Using With

products table have forieng_key brands_id, every product related to one brand. i make the relation but in select product with brands I got error Call to undefined relationship [brands] on model [App\Products].

productsModel

class Products extends Model{
    protected $table = 'products';
    protected $fillable = [
        'cats_id','brands_id','name_ar','name_en','slug_ar','slug_en','tags_ar','tags_en','code','qty','color' 'size','price','copouns_id','discount','video','hot_deal','img','sm_img','active','admins_id','discription' ];

    public function brands(){
        return $this->belongsTo('App\Brands');
    }
}

BrandsModel

class Brands extends Model
{
    protected $table = 'brands';
    protected $fillable = [
        'brands_name_ar','brands_name_en', 'slug_ar', 'slug_en', 'photo', 'active', 'admin_id'
    ];
    public function products(){
        return $this->hasMany('App\Products');
    }

}

ProductsController

    public function index(){
        $product = Products::select('id','name_ar','qty','code','price','img','active','admins_id','brands_id')
            ->with('brands:id,brands_name_ar')
            ->orderBy('id','DESC')->paginate(20);
        return view ('admin.product.indexproduct',compact('product'));
    }

plz how get products with brand related to it

Jun
27
1 month ago
Activity icon

Started a new Conversation Multi Upload File Using Class.upload.php / Ajax

i use class.upload.php to upload files in laravel using ajax I try to upload multi-file ajax code

$("#uploadMultiFiles").change(function () { var formData = new FormData(); var filesLength=document.getElementById('uploadMultiFiles').files.length; for(var i=0;i<filesLength;i++){ formData.append('file[]',document.getElementById("uploadMultiFiles").files[i].name); } $.ajax({ headers: { 'X-CSRF-TOKEN': "{{ csrf_token() }}" }, url: "{{ route('uploadfiles') }}", method: "POST", data: formData, processData: false, contentType: false, cache: false, }); }); laravel upload function public function upload(Request $request){

    $files = array();
    $f=$request->file;
    foreach ($_files['file'] as $k => $l) {
        foreach ($l as $i => $v) {
            if (!array_key_exists($i, $files))
                $files[$i] = array();
            $files[$i][$k] = $v;
        }
    }

    foreach ($files as $file) {
        $handle = new \Verot\Upload\Upload($file);
        if ($handle->uploaded) {
            $handle->process(public_path('images').'/cats/');
            if ($handle->processed) {
                return $handle->file_dst_name;
            } else {
                return 'error : ' . $handle->error;
            }

        } else {
            return 'Error: Error Here Cn Do Any Things' . $handle->error;
        }
        unset($handle);
    }
}

i got error Undefined index: file" I TRY TO USE

i got this error "Invalid argument supplied for foreach()"

when i print dd(($request->file) uploaded file printed successfully

Jun
03
2 months ago
May
30
2 months ago
Activity icon

Replied to Get Limit Of Child Eloquent

this means I must create a new function to determine Limit, there is another way to do it from eloquent

Activity icon

Replied to How Get Parent If Child Have Data

Track Model

    public function Course(){
        return $this->hasMany('App\Course');
    }

Course Model

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

eloquent Code

$track=Track::select('id','track_name')->with(['Course'=>function($q){
    $q->select('id', 'course_title', 'track_id', 'link', 'num_student','status')->orderBy('id','DESC')->take(4);
}])->orderBy('id','DESC')->take(4)->get();

I want to retrieve track and course if the track has a course when I use has that gives me an error

Activity icon

Started a new Conversation How Get Parent If Child Have Data

in example i want to get Tracks, if (Tracks have Course), plz how do that

$track=Track::select('id','track_name')->with(['Course'=>function($q){
    $q->select('id', 'course_title', 'track_id', 'link')->where('status',1)->orderBy('id','DESC')->limit(4);
}])->orderBy('id','DESC')->limit(4)->get();

i try to use whereHas but dosent work

May
29
2 months ago
Activity icon

Started a new Conversation Get Limit Of Child Eloquent

hi i want to get just 4 Course, but this code not working, working just on Track

$track=Track::select('id','track_name')->with(['Course'=>function($q){
      $q->select('id', 'course_title', 'track_id', 'link')->where('status',1)->orderBy('id','DESC')->limit(4);
}])->orderBy('id','DESC')->limit(4)->get();