Sonu

Sonu

Member Since 4 Years Ago

Lahore

Experience Points 14,175
Experience Level 3

825 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 1
Lessons
Completed
Best Reply Awards 5
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

16 Dec
2 years ago

Sonu started a new conversation On Composer Update Class Not Found Error

After quite long time i run composer update command and get this error

I am using Laravel 5.1 version


  [Symfony\Component\Debug\Exception\FatalErrorException]
  Class 'Cviebrock\EloquentSluggable\SluggableServiceProvider' not found

where as this package run perfectly before composer update. What should i do now ?

06 Apr
3 years ago

Sonu left a reply on View Composer Help Needed

@Alizey1 do this like


view()->composer('Frontend.listing.view',function($view)
{
    $subchild = Request::segment(2);
        $view->with('menus2', SubCategory::where('slug','=',$subchild)->has('childcategory')->get());
});
05 Apr
3 years ago

Sonu left a reply on Method Render Does Not Exist

@thomaskim Thanks its work.

Sonu started a new conversation Method Render Does Not Exist

i want to show popular products according to their view count. Function

public function popular($parent = null,$child = null)
  {     
    $products =  Product::with('subcategory')->with('subchild')->paginate(16)->sortByDesc('view_cache');
    return view('Frontend.listing.popular')->with(['products'=>$products]);
   }

at View

echo $products->render();

why i am getting that error ? How can i fix it

20 Feb
3 years ago

Sonu left a reply on Show Blogs Having More Views

You can use this

Blog::take(8)->get()->sortByDesc('view_cache');
09 Feb
3 years ago

Sonu left a reply on View Composer Not Working

Wtf My Path was wrong Silly Mistake :/

'Frontend.includes.header'  There is Backend Instead Of Froentend `Backend.includes.header`

Sonu left a reply on View Composer Not Working

@ARCANEDEV Yes i got that error at my view page when i pass it to foreach. I am only concern with AppServiceProvider Becuse if return the Result its shows Nothing

Sonu left a reply on View Composer Not Working

@tykus_ikus its typo error... Category::get()

Sonu left a reply on View Composer Not Working

@bobbybouwmann its not working at all.. This way works in 5.1 As well As 0.

If i simply do that

$category = '';
// Notice the "use" statement
view()->composer('Frontend.includes.header', function($view) use ($category)
{
    $view->with('category',  Category::->get());
});

return $category;

Nothing Happens.. dont get any record. Not sure why its happenig :(

Sonu left a reply on View Composer Not Working

@Mariam same error :(

Sonu started a new conversation View Composer Not Working

WHy view composer not working in Laravel 5.2 :/

My Function

public function boot()
    {
        $category="";
        view()->composer('Frontend.includes.header',function($view)
        {
            $view->with('category',  Category:where('created_at', '>=', Carbon::today())->get());
        });
        
    }

when i get this variable $category at my view i got error of Un defined Variable WHy

24 Nov
3 years ago

Sonu left a reply on Redirect Problem

if just changed this like

$redirectUrls->setReturnUrl(action('Frontend\MyPaypalPaymentController@getDone'));
$redirectUrls->setCancelUrl(action('Frontend\MyPaypalPaymentController@getCancel'));

now its giving me error that

Frontend\MyPaypalPaymentController@getCancel not defined.

While in same controller i have this

    public function getDone(Request $request)
    {
        $id = $request->get('paymentId');
        $token = $request->get('token');
        $payer_id = $request->get('PayerID');
        $payment = PayPal::getById($id, $this->_apiContext);
        $paymentExecution = PayPal::PaymentExecution();
        $paymentExecution->setPayerId($payer_id);
        $executePayment = $payment->execute($paymentExecution, $this->_apiContext);
        return "Yahoo";
    }
    

    
    public function getCancel()
    {
        return "Cancle";
    }

Whats going wrong now getdone function is working fine

Sonu left a reply on Redirect Problem

@thomaskim here it is and Namespace is Frontend

Route::group(['namespace' => 'Frontend'], function() {
    Route::post('/payment', 'MyPaypalPaymentController@getCheckout');
});

Sonu started a new conversation Redirect Problem

I am using https://github.com/net-shell/laravel-paypal/tree/master Paypal Package and Having Issue with the Redirects.

Here is the Error

Action App\Http\Controllers\MyPaypalPaymentController@getDone not defined.

Here is My Controller

   public function getCheckout()
   {
        $payer = PayPal::Payer();
        $payer->setPaymentMethod('paypal');
    
        $amount = PayPal:: Amount();
        $amount->setCurrency('EUR');
        $amount->setTotal(42);
        $transaction = PayPal::Transaction();
        $transaction->setAmount($amount);
        $transaction->setDescription('What are you selling?');
    
        $redirectUrls = PayPal:: RedirectUrls();
        $redirectUrls->setReturnUrl(action('MyPaypalPaymentController@getDone'));
        $redirectUrls->setCancelUrl(action('MyPaypalPaymentController@getCancel'));
    
        $payment = PayPal::Payment();
        $payment->setIntent('sale');
        $payment->setPayer($payer);
        $payment->setRedirectUrls($redirectUrls);
        $payment->setTransactions(array($transaction));
    
        $response = $payment->create($this->_apiContext);
        $redirectUrl = $response->links[1]->href;
        return Redirect::to($redirectUrl);
    }
    
    
    public function getDone(Request $request)
    {
        $id = $request->get('paymentId');
        $token = $request->get('token');
        $payer_id = $request->get('PayerID');
        $payment = PayPal::getById($id, $this->_apiContext);
        $paymentExecution = PayPal::PaymentExecution();
        $paymentExecution->setPayerId($payer_id);
        $executePayment = $payment->execute($paymentExecution, $this->_apiContext);
        return "Yahoo";
    }

Now i have the get done function why its saying Not Defined

Action App\Http\Controllers\MyPaypalPaymentController@getDone not defined.

i am using name space how can i give that to

$redirectUrls->setReturnUrl(action('MyPaypalPaymentController@getDone'));

Any Help

24 Oct
3 years ago

Sonu left a reply on Laravel Designer

@christopher Yes i try compose install now its works

Sonu left a reply on Laravel Designer

I just select the packages and download that. but when i run composer update it gives me error. Don't update why

Sonu left a reply on Laravel Designer

@bestmomo its really helpfull and time saving in developemt :)

Sonu left a reply on Laravel Designer

@bestmomo lovely work :) also i think there is some notification package also like Toastr notification or others..

Great job

21 Oct
3 years ago

Sonu left a reply on Laravel 5.1 Resest Password

@bashy Yes its true 'pretend' => true,. i am receving emails on user registration . but don't on password reset. My this code works perfect in Laravel 5

Sonu started a new conversation Laravel 5.1 Resest Password

Hey guys i am facing iccuse at reset password in Laravel 5.1 My code works but i did'nt get any email . And also Mandrill don't show any email sent. But i receive email on user registration. Here is my code

public function getEmail(Request $request)
    {
        return view('Frontend.auth.password');
    }
    
    public function postEmail(Request $request)
    {
        $this->validate($request, ['email' => 'required|email']);
        $response = $this->passwords->sendResetLink($request->only('email'), function($m)
        {
            $m->subject($this->getEmailSubject());
        });

        switch ($response)
        {
            case PasswordBroker::RESET_LINK_SENT:
                $message = "Password recovery link has been send to your email address";
                Toastr::success($message, $title = null, $options = []);
                return redirect()->back();
            case PasswordBroker::INVALID_USER:
                return redirect()->back()->withErrors(['email' => trans($response)]);
        }
    }

    protected function getEmailSubject()
    {
        return isset($this->subject) ? $this->subject : 'Your Password Reset Link';
    }
    
    public function getReset($token = null, Request $request)
    {
        if (is_null($token))
        {
            throw new NotFoundHttpException;
        }
            $messages = "Create your new password";
            Toastr::info($messages, $title = null, $options = []);
            return view('Frontend.auth.reset')->with('token', $token);
    }

In Success case i recived the Message Password recovery link has been send to your email address

THis code works in Laravel 5 like a charm. but not sending email with 5.1 whats should i have to do. ?

15 Oct
3 years ago

Sonu left a reply on Cascade Error

No :) Thanks

Sonu left a reply on Cascade Error

@bobbybouwmann have a look

Schema::create('categories', function($table)
        {
            $table->increments('id')->unsigned();
            $table->string('title');
            $table->string('slug')->unique();
            $table->string('description')->nullable()->default(NULL);
            $table->timestamps();
            $table->softDeletes();
        });

Sub Category

 Schema::create('subcategories', function($table)
        {
            $table->increments('id')->unsigned();
            $table->string('title');
            $table->string('slug')->unique();
            $table->string('description')->nullable()->default(NULL);
            $table->integer('category_id')->unsigned();
            $table->timestamps();
            $table->softDeletes();
            $table->foreign('category_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('cascade');
        });

And Sub Child Category

 Schema::create('childcategories', function($table)
        {
            $table->increments('id')->unsigned();
            $table->string('title');
            $table->string('slug')->unique();
            $table->string('description')->nullable()->default(NULL);
            $table->integer('category_id')->unsigned();
            $table->integer('sub_cat_id')->unsigned();
            $table->timestamps();
            $table->softDeletes();
            $table->foreign('category_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('sub_cat_id')->references('id')->on('subcategories')->onUpdate('cascade')->onDelete('cascade');
        });

and then product table i just pass category_id,sub_cat_id and sub_child_id

Sonu started a new conversation Cascade Error

I am get error on cascade

 Schema::create('products', function($table)
        {
            $table->increments('id')->unsigned();
            $table->string('title');
            $table->string('slug')->unique();
            $table->integer('category_id')->unsigned()->nullable();
            $table->integer('sub_cat_id')->unsigned()->nullable();
            $table->integer('sub_child_id')->unsigned()->nullable();
            $table->boolean('responsive');
            $table->boolean('high_resolution');
            $table->mediumText('compatible');
            $table->mediumText('browsers');
            $table->mediumText('files_included');
            $table->boolean('documentation');
            $table->binary('thumb');
            $table->json('screenshots');
            $table->text('description')->nullable()->default(NULL);
            $table->timestamps();
            $table->softDeletes();
            $table->foreign('category_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('sub_cat_id')->references('id')->on('subcategories')->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('sub_child_id')->references('id')->on('childcategories')->onUpdate('cascade')->onDelete('cascade');
        });

Here is got error message

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`bundle`.`products`, CONSTRAINT `products_sub_cat_id_foreign` FOREIGN KEY (`sub_cat_id`) REFERENCES `subcategories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)
14 Oct
3 years ago

Sonu started a new conversation Fillable When Array

Can we use fillable function when we have multiple values through form. Like i have Multiple Categories Again Project So My Select Box is

 <select multiple="multiple"  style="display:none;" name="sub_cat_id[]" id="sub_cat_id">
   // Ajax Data Populated                                           
</select>

My Model

protected $sluggable = [
        'build_from' => 'title',
        'save_to'    => 'slug',
    ];
    
    protected $table = 'products';
    
   protected $fillable = ['title', 'slug', 'description','category_id','sub_cat_id'];
    
    protected $hidden = ['updated_at','created_at','deleted_at'];

If i simply uses $products = Product::create(Input::all()); then its works for only one record if uses. How can i use fill able when i have multiple values from form. Or Just just use foreach loop in my controller to get that ids in loop and insert them ?

12 Oct
3 years ago

Sonu left a reply on How To Use Eloquent-sluggable In Controller

Silly Mistake its works fine i am giving wrong name in Form input :(

<input type="text" name="title" id="title" class="gui-input" placeholder="Enter Category Name...">

i am using name="name" :( silly Thanks @bobbybouwmann for your valueable time

Sonu left a reply on How To Use Eloquent-sluggable In Controller

How strange i have title field in my db Here is Schema that i written

public function up()
    {
        Schema::create('categories', function($table)
        {
            $table->increments('id')->unsigned();
            $table->string('title');
            $table->string('slug')->unique();
            $table->string('description')->nullable()->default(NULL);
            $table->timestamps();
            $table->softDeletes();
        });
    }

Sonu left a reply on How To Use Eloquent-sluggable In Controller

@bobbybouwmann after correcting the syntax getting the same error Column 'slug' cannot be null

Column 'slug' cannot be null (SQL: insert into `categories` (`description`, `slug`, `updated_at`, `created_at`) values (asdasdadsdasdasdasdasdasdasdasd, , 2015-10-12 16:54:34, 2015-10-12 16:54:34))

Sonu started a new conversation How To Use Eloquent-sluggable In Controller

how we can use eloquent-sluggable in our controller My Model

use Cviebrock\EloquentSluggable\SluggableInterface;
use Cviebrock\EloquentSluggable\SluggableTrait;
class Category extends Model implements SluggableInterface
{
    use SoftDeletes;
    
    use SluggableTrait;
    
     protected $sluggable = [
        'build_from' => 'title',
        'slug'    => 'slug',
    ];
    
    protected $table = 'categories';
    
    protected $fillable = ['title', 'slug', 'description'];
    
    protected $hidden = ['updated_at','created_at','deleted_at'];
    
    public function sub_cats()
    {
        return $this->hasMany('App\Sub_Category');
    }

}

And Controller

 public function store(Request $request)
    {
        $category = Category::create($request->all());
        return redirect()->back();
    }

but slug is not generated. Here is the package link https://github.com/cviebrock/eloquent-sluggable

Sonu left a reply on Laravel 5.1 Auth Sign In Help Needed

@pmall thanks its works :)

Sonu started a new conversation Laravel 5.1 Auth Sign In Help Needed

Geting Error Call to a member function attempt() on a non-object At Auth Controller

I am doing sign In Here is the code

public function getLogin()
    {
        return view('Backend.auth.login');
    }
    
    
    public function postLogin(Request $request)
    {
        $this->validate($request, [
            'email' => 'required|email', 'password' => 'required',
        ]);

        $credentials = $request->only('email', 'password');
        $credentials['is_admin'] = 1;
        
        if ($this->auth->attempt($credentials, $request->has('remember')))
        {
             $username = Auth::user()->first_name;
             Session::flash('success',"Welcome Back $username You are successfully Signed In!");
             return redirect()->intended($this->redirectPath('/admin/dashboard'));
        }

        return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors([
                        'email' => $this->getFailedLoginMessage(),]);
    }

This code is working like a charm In Laravel 5 But In 5.1 its gave me error of attempt() on a non-object how can i fix that ?

10 Oct
3 years ago

Sonu left a reply on Why Laravel 5.1 Don't Have Bootstrap Included

@sgraewe how can i run npm install on localhost

Sonu started a new conversation Why Laravel 5.1 Don't Have Bootstrap Included

WTF Why Laravel 5.1 Don't Have Bootstrap Included like in Laravel 5 How can i add bootstrap in 5.1 Any help guyz

Sonu left a reply on Why Laravel 5.1 Not Install With Auth Controllers

@jlrdw Sorry i don't understand what you are saying

Sonu started a new conversation Why Laravel 5.1 Not Install With Auth Controllers

I am just trying to instal a fresh Laravel 5.1 with composer but its does not install with defualt Auth controller like in laravel 5

Here is the command

composer create-project laravel/laravel=5.1.11 realApp --prefer-dist
19 Sep
3 years ago

Sonu left a reply on How We Can Limit Over Search Query

Means that query just return only 2000 records which word user search. its it possible. ?

Sonu left a reply on How We Can Limit Over Search Query

@martinbean i user search chicken then query search all records related to chicken in 10 lakh records. i just want he can only get 2000 records not all.

Sonu started a new conversation How We Can Limit Over Search Query

I want to know that there is any way to limit the search query. Actually i have 10 Lakh records in Db. For example if a user search chicken then its search from all data base and generate the pagination. so its generate alot of pages.

I want to just search on 2000 records only. How can i do that. Here is my search function

$input = trim(Input::get('diet_search'));
    $exp = explode(' ', $input);
    $s = '';
    $c = 1;
    foreach ($exp AS $e)
    {
        $s .= "+$e*";
    
        if ($c + 1 == count($exp))
            $s .= ' ';
        $c++;
    }
    $query = "MATCH (diet_name) AGAINST ('$s' IN BOOLEAN MODE)";    
    $result = Diets::whereRaw($query)->paginate(10);
    return view('Front.my_health.health')->with('result',$result);

Sonu started a new conversation How To Detect Device And Redirect To Mobile Or Tablet App

How to detect device and redirect to mobile or tablet App. I meas if a user access website from mobile then a popover appers and says to download this. for Ios and Android

09 Sep
3 years ago

Sonu started a new conversation Is Auth::user() Works For Api ?

i am making Api service for both Android and ISO i just want to know that Auth::user() works for APi. Here is my Function

public function postLogin(Request $request)
{
        $this->validate($request, ['email' => 'required|email', 'password' => 'required']);
        
        if ($this->signIn($request)) {
            $user = Auth::user();
            return response()->json($user); 
            exit;
            
        }
        else
        {
            return response()->json(['error' => 'invalid_credentials','data'=>'Your email is not activated or your password is Invalid'], 404);
            exit;
        }
}

Now if user credentials are match then he loged in and i have to send current user table data to Api. Can i send using $user = Auth::user(); return response()->json($user); or i have to fatch data using another way ?

03 Aug
3 years ago

Sonu left a reply on Having Auth Issue In Laravel 5

And this is Login function for frontend

public function postLogin(Request $request)
{
        $this->validate($request, ['email' => 'required|email', 'password' => 'required']);
        if ($this->signIn($request)) {
            $username = Auth::user()->firstname. " ". Auth::user()->lastname;
            $get_combinations = UserCombinations::where('user_id',Auth::user()->id)->pluck('is_combination_created');
            $message = "You are logged in successfully $username";
            Toastr::success($message, $title = null, $options = ['positionClass']);
            Toastr::clear();
                $check = Auth::user()->is_profile_completed;
                if($check=="1" && $get_combinations=="0")
                {
                    return redirect('/health_profile');
                }
                else if($check=="1" && $get_combinations=="1")
                {
                    return redirect('/my-health');
                }
                else
                {
                    return redirect('/profile');
                }
        }
        $message1 = "Your email is not activated or your password is Invalid";
        Toastr::info($message1, $title = null, $options = []);
        Toastr::clear();
        return redirect()->back();
}

Sonu left a reply on Having Auth Issue In Laravel 5

if user munally goes to admin url then my above function works fine,

Sonu left a reply on Having Auth Issue In Laravel 5

@absiddiqueLive yes i am using laravel Auth. for backend i used Laravel 5 defualt Auth system and fro front end i make a new custom controller. every thing is working fine. the problem is if user is logged in from front end he can also access the admin panel where as he has no access to panel

Backend Controller

public function postLogin(Request $request)
    {
        $this->validate($request, [
            'email' => 'required|email', 'password' => 'required',
        ]);
        $credentials = $request->only('email', 'password');
        $credentials['is_admin'] = 1; // Add is_admin to the credentials to insure the user has admin account
        if ($this->auth->attempt($credentials, $request->has('remember')))
        {
             $name = Auth::user()->firstname;
             Session::flash('success',"Welcome Back $name You are successfully Signed In!");
             return redirect()->intended($this->redirectPath('/admin/dashboard'));
        }
        return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(['email' => $this->getFailedLoginMessage(),]);
    }

i also make a check $credentials['is_admin'] = 1; // Add is_admin to the credentials to insure the user has admin account

Sonu started a new conversation Having Session Issue In Laravel

Guys i am facing the problem of login. Actually my problem is if a user logged in from the front end and he try to go to admin panel then he also successfully logged in to admin panel. Where as i make a check if user has admin acess he can only login.. and it works perfectly when user manually goes to admin link. he can't loged in if he don;t have permission.

But when user is logged in why its not working :(

30 Jul
3 years ago
29 Jul
3 years ago

Sonu started a new conversation Email Conformation Help Needed

Guys i just want some help needed according to email conformation. My problem is when a user register to website i send a confirmation email to that user. When user click on the verification link it work fine and her account is confirmed but. if user click again on email verification link then i got error No query results for model [App\User] How can i fix that. Here is my functions

public function confirmEmail($token)
   {
        User::whereToken($token)->firstOrFail()->confirmEmail();
        $message = "Your email has been confirmed. Please login";
        Toastr::success($message, $title = null, $options = []);
        return redirect('/auth/login');
   }

confirm email

public function confirmEmail()
    {
        $this->verified = true;
        $this->token = null;
        $this->save();
    }

if user click first time on that confirmation link every thing works fine. He he again clikck on that then got error No query results for model [App\User].

27 Jul
3 years ago

Sonu left a reply on Return Redirect Back With Form Inputs

should i have to metion each input ?

Sonu started a new conversation Return Redirect Back With Form Inputs

How we can send old form input values back to form in case of any error Here is my code if user filled wrong captcha then redirect back to form with all inputs

$rules = ['captcha' => 'required|captcha'];
            $validator = Validator::make(Input::all(), $rules);
            if ($validator->fails())
            {
                echo '<p style="color: #ff0000;">Incorrect!</p>';
            }
            else
            {
                $user = User::create($request->all());
                $profile = new Profile;
                $profile->userid=$user->id;
                $profile->save();
                $mailer->sendEmailConfirmationTo($user);
                $message = "An activation email has been sent to your email address to verify your account";
                Toastr::success($message, $title = null, $options = []);
                return redirect()->back();
            }
17 Jul
3 years ago

Sonu left a reply on Can We Stop View Cache In Laravel 5

i am using artesaos/seotools tools when ever i share a link on Fb. they don't get my Meta keyword and shows all things from storage/framework/view cache . if is saw the page source then i have all new things like content image title etc, but they always show data from my very old view cache. How can i clear cache on live server.