baloch

baloch

Member Since 1 Year Ago

Experience Points 640
Experience Level 1

4,360 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.

03 Sep
11 months ago

baloch left a reply on This Page Isn’t Working ( Http://prntscr.com/kq4qar ). Importing A Large Excel File

@newbie360 not always after 1000 records, it varies.

i have seen the logs but i can't understand it, any help? @Cronix @newbie360

baloch started a new conversation This Page Isn’t Working ( Http://prntscr.com/kq4qar ). Importing A Large Excel File

i'm importing an excel file which has more than 100,000 records and then i'm saving these records in my database through a foreach loop. Efficiency isn't my top priority as this process will be used only once. after the code inserts about 1000 records then the process stops and i face this page ( http://prntscr.com/kq4qar ) . any help would be highly recommended.

31 Aug
11 months ago

baloch left a reply on How To Prevent Eloquent From Converting Empty String To Null Automatically?

@crnkovic the script thingy is not working, instead of entering this " " in the db it is entering null and hence the column can not be empty exception shows.

baloch left a reply on How To Prevent Eloquent From Converting Empty String To Null Automatically?

@crnkovic it is required in the current system but right now i'm importing data from the excel sheet of the old system they didn't have the company field required, but now it's required.

baloch left a reply on How To Prevent Eloquent From Converting Empty String To Null Automatically?

@Cronix the result of dd is null

@Krisell i'm not submitting a form, i'm importing data from an excel sheet. In the foreach loop this is some of the code that i'm using. the error occurs on the last line.

$mas = new Masterdealer();
                        $mas->macola_id = (int)$value->id;
                        $mas->created_at = $value->dateentered;
                        $mas->status = 1 - (int)$value->inactive;
                        $mas->fname = $value->first;
                        $mas->lname = $value->last;
                        $mas->company = $value->company == null ? " " : $value->company;

baloch left a reply on How To Prevent Eloquent From Converting Empty String To Null Automatically?

@Cronix @click @Krisell i have tried this but it's still not allowing me to send empty string :(

baloch started a new conversation How To Prevent Eloquent From Converting Empty String To Null Automatically?

i'm trying to enter an empty string in a varchar column that is not nullable but laravel is converting that empty string to null when entering the record in the DB and hence i'm getting ** Integrity constraint violation: 1048 Column 'company' cannot be null** how to overcome this?

17 Jul
1 year ago

baloch left a reply on Laravel Redirect Back To Post Route, I Get MethodNotAllowedHttpException

@Snapey this is a good idea but what if i have to use those post values in the view?

29 Jun
1 year ago

baloch left a reply on Laravel Redirect Back To Post Route, I Get MethodNotAllowedHttpException

@AlexDemin because when the request comes to this url Route::post('/confirmPuchasedPacks','[email protected]'); then in the confirmPuchasedPacks method i process the request and make some variables. Then I return a view and pass those variables to that view. so basically the view requires those variables.

baloch started a new conversation Laravel Redirect Back To Post Route, I Get MethodNotAllowedHttpException

At first on a get request i show a form, on submitting it, it goes to a post url does some working in the controller and then returns another view which has a form. after submitting this form i validate some things and if the validation fails i want to redirect back with some errors but unfortunately laravel isn't allowing me to redirect back to a post method. Is there any way i can accomplish this?

i have seen this answer on laracast https://laracasts.com/discuss/channels/laravel/redirect-back-to-post-route-i-get-methodnotallowed-exception but i couldn't grasp the recommendation

these are my routes in the order described above.

Route::get('/purchasePacks', '[email protected]')->name('purchasePacks');
  Route::post('/confirmPuchasedPacks','[email protected]');
  Route::post('/storeOrder','[email protected]');

below is the redirection code in the storeOrder method. which redirects back to the post url

Alert::message("Unable to complete your payment at the moment.",'Please try again later.',"error");
        return back()->withInput();
12 Jun
1 year ago

baloch started a new conversation Eager Loading And Union In Eloquent.

I have a table Uuids which has a morph relation with dealers, masterdealers, admins and customers table. I need to get the email addresses from all the above mentioned user types tables along with their uuids from the uuids table. i'm using union to get all the emails from dealers, masterdealers, admins and customers table but i want to somehow eagerload their uuids too.

my desired output would be something like this :

{
email: [email protected]
uuid: 1
},
{
email: [email protected]
uuid: 5
},
{
email: [email protected]
uuid: 11
}```

i have tried `DB::select("SELECT email FROM customers
            UNION SELECT email FROM dealers
            UNION SELECT email FROM masterdealers
            UNION SELECT email FROM admins");`

and it gives me all the emails from these 4 tables
24 May
1 year ago

baloch left a reply on Can't Access Parent View's Variable In Child View.

@Vilfago yes i thought of this too and it works too but the problem in this approach is that as home and master gets loaded on the same url (because home extends masters) so the view composer is ran twice due to this the join query in the view composer is run twice for the same url

                        $join->on('carts.product_id', '=', 'products.id')
                            ->where('carts.customer_id', $customer->id);
                        })
                        ->select(DB::raw('sum(carts.product_quantity*products.cost) AS totalCart'))
                        ->get();

baloch left a reply on Can't Access Parent View's Variable In Child View.

if i write <h1>{{$totalCart}}</h1> this in master.blade. it works and shows the variable's value but when i use the same link in home view which extends master view, an exception is thrown that variable totalCart is undefined

baloch left a reply on Can't Access Parent View's Variable In Child View.

@Vilfago laravel version 5.4. i'm able to use this variable in master.blade.php but can't access it in home.blade which basically extends master.blade.php


namespace App\Http\ViewComposers;

use App\Cart;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class CartComposer
{
    public $totalCart;
    /**
     * Create a movie composer.
     *
     * @return void
     */
    public function __construct()
    {
        $customer=Auth::guard('customer')->user();
        if(isset($customer) != 1) 
        {
            $this->totalCart = 0; 
        }
        else
        {
            $cart = Cart::join('products', function ($join) use ($customer) {
                        $join->on('carts.product_id', '=', 'products.id')
                            ->where('carts.customer_id', $customer->id);
                        })
                        ->select(DB::raw('sum(carts.product_quantity*products.cost) AS totalCart'))
                        ->get();

            if($cart[0]->totalCart == null) {
                $this->totalCart = 0;
            }
            else {
                $this->totalCart = $cart[0]->totalCart;
            }
        }
    }

    /**
     * Bind data to the view.
     *
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    {
        $view->with('totalCart', $this->totalCart);
    }
}

baloch started a new conversation Can't Access Parent View's Variable In Child View.

i have a home.blade.php view which extends master.blade.php but due to some reason i cant use the variable in home view that is being passed to master.blade.php by a view composer. is there any way i can use the variable in the home view?

23 May
1 year ago

baloch left a reply on What Is The Size Of My Current Session?

i'm storing data in session like this and some other data, how can i find out the total size of my current session

$cart = Cart::where('customer_id',$customer->id)->get();
                    Session::put('cart', $cart);

baloch started a new conversation What Is The Size Of My Current Session?

there are 2 parts of my question.

  1. how can i find out the the current size of the session (in laravel) that i'm using.
  2. what is the maximum size of php session that i can use in laravel? (i searched the stackoverflow and i think the answer to this part is 128MB)
23 Apr
1 year ago

baloch started a new conversation Should I Use Conditions In Methods Or Make Different Methods?

Currently i have 2 options, in my controller i can either make different methods or i can make a single method and differentiate the working by using conditions. Let me elaborate.

  1. I can make two methods dealer() and subDealer() and do their workings separately.

  2. I make a single dealers() method and in that i can check if that is a dealer or a sub dealer by using a single if statement. as majority of the work of these two will be same.

which is better?

11 Apr
1 year ago

baloch left a reply on Apply Sql Case On Select All In Laravel

@wilk_randall can you write me an eloquent statement through which i can get all the columns of all the products in the db where('is_archive', 0), and if pick_8 is '1' then return pick_8 as 'true' else if pick_8 is '0' then return pick_8 as 'false'

baloch left a reply on Apply Sql Case On Select All In Laravel

@wilk_randall hey! i cant apply accessor because there are places where i dont want to cast it. it's just in this case because i am exporting the data to excel file and i dont want to show the pick_8 as 1 and 0 rather i want to check if the value of pick_8 is '1' then in the model get it as 'True' else 'False'.

baloch started a new conversation Apply Sql Case On Select All In Laravel

I want to get all the columns from the products table and apply sql case on pick_8 and pick_12 columns only but to do this i have to write all the column names in select. Is there any way in laravel where i can apply the simple get() method to retrieve all the columns with applying case on only 2, without having to write all the column names manually.

$products=Product::where('is_archive',0)->select('humanId','name','cost','retailPrice','memberPrice','points', DB::raw('(CASE WHEN pick_8 = 1 THEN "True" ELSE "False" END) AS pick_8'), DB::raw('(CASE WHEN pick_12 = 1 THEN "True" ELSE "False" END) AS pick_12'))->get()->toArray();

10 Apr
1 year ago

baloch left a reply on Query Builder - Inside Insert Query I Want To Implement A For Loop Over The Array To Insert Multiple Records In One Go

@ekhlas i found the solution, i hope it helps someone else too


for ($i=0; $i <count($memberships) ; $i++){
    $array[] = array(
        'membership_id' => $memberships[$i],
        'masterdealer_id' => $dealer,
        'dealer_id' => null,
        'user' => 'masterdealer',
        'operation' => 'Accessible',
        'admin_id' => $data['id'],
        'created_at' => $now->format('Y-m-d H:i:s'),
        'updated_at' => $now->format('Y-m-d H:i:s')
    );
}

DB::table('accessible_membership_logs')->insert($array);


baloch left a reply on Query Builder - Inside Insert Query I Want To Implement A For Loop Over The Array To Insert Multiple Records In One Go

@ekhlas this is the exception it's showing now

Assignments can only happen to writable values

in adminController.php (line 1236)```

baloch started a new conversation Query Builder - Inside Insert Query I Want To Implement A For Loop Over The Array To Insert Multiple Records In One Go

what i want to achieve is that inside the DB query i insert all the records in one go so that the query doesn't run many times. the following code doesn't allow me to use the for loop inside the array. kindly help.

        {
            if($request['accessibleTodealers']!='' || $request['accessibleTodealers']!=null)
            {
                $memberships=explode(",",$request['accessibleTodealers']);
                $membe = array();
                $now = Carbon::now();
                DB::table('accessible_membership_logs')->insert([
                    array(
                        for ($i=0; $i <count($memberships) ; $i++){
                        array(
                            ['membership_id']=$memberships[$i],
                            ['masterdealer_id']=$dealer,
                            ['dealer_id'] = null,
                            ['user'] = 'masterdealer',
                            ['operation'] = 'Accessible',
                            ['admin_id'] = $data['id'],
                            ['created_at'] = $now->format('Y-m-d H:i:s'),
                            ['updated_at'] = $now->format('Y-m-d H:i:s')
                        )}
                    )
                ]);
                Alert::message("","Changes Updated.!","success");
                return redirect()->intended('/admin/masterDealerDetail/'.$dealer); 
            }
        }```