Rymercyble

Rymercyble

Member Since 1 Year Ago

Experience Points 2,400
Experience Level 1

2,600 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 14
Lessons
Completed
Best Reply Awards 0
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.

29 Apr
3 weeks ago

Rymercyble left a reply on Using Logic In Controllers

than-q for answers

28 Apr
3 weeks ago

Rymercyble started a new conversation Using Logic In Controllers

Hello, I would be very happy if someone turns me to the right way. At the moment I'm using controllers probably in the wrong way (I'm quite not sure) When I need for example manage articles I'm using 1 controller for /articles (get,post) - list of all or filtered articles /article (get,post) - showing 1 whole specific article and often even more than 4 methods. Is that ok or should I divide it ? Also, I'm probably putting too much logic to my methods for example

public function people()
    {
        $search = Request::has('search') ? Request::get('search') : 0;
        if ($search) {
            if (Request::get('min_age') == ''){
                $min_age = '10';
            } else {
                $min_age = Request::get('min_age');
            }
            if (Request::get('max_age') == ''){
                $max_age = '120';
            } else {
                $max_age = Request::get('max_age');
            }

            $carbon = Carbon::today();
            $carbon_max = Carbon::today();
            $max_age += 1;
            $year_min = $carbon->year - $min_age;
            $year_max = $carbon_max->year - $max_age;
            $carbon_min = $carbon->setDate($year_min, $carbon->month, $carbon->day)->toDateString();
            $carbon_max = $carbon_max->setDate($year_max, $carbon->month, $carbon->day)->toDateString();

            $users = User::when(!empty(Request::get('country')),function ($query){
                $query->where('country', Country::where('name', Request::get('country'))->select('id')->first()->id);
            })->when(!empty(Request::get('physical_gender')),function ($query){
                $query->where('physical_gender', Physical_gender::where('name', Request::get('physical_gender'))->select('id')->first()->id);
            })->when(!empty(Request::get('language')),function ($query){
                $query->whereHas('languages', function($query){
                    $query->where('name', Request::get('language'));
                });
            })->when(!empty(Request::get('language_want')),function ($query){
                $query->whereHas('unknownLanguages', function($query){
                    $query->where('name', Request::get('language_want'));
                });
            })->whereBetween('date_of_birth', [$carbon_max, $carbon_min])
                ->select('nick_name','first_name','last_name','date_of_birth','hidden_id')
                ->get();
        } else {
            $users = Sentinel::getUserRepository()->select('nick_name','first_name','last_name','date_of_birth','hidden_id')->get();
        }

        return view('people', compact('users'));
    }

if this is wrong where i should store logic ?

14 Mar
2 months ago

Rymercyble left a reply on Using Data From Controller In Different Controller

@JLRDW - but I'm not using login system

I solved it like this

public function postTrade(Request $request){
    $key = "key";
        Session::put($key, $request->all());
        return redirect('/stage2')->with(['key' => $key]);
    }
<script>
    sessionStorage.setItem("key", "{{ session('key') }}");
</script>
<form action="" method="POST">
    @csrf
    <input type="hidden" name="key" id="key">
    <script>
        document.getElementById("key").value = sessionStorage.getItem("key");
    </script>
    <input type="submit" name="pay" value="Pay">
</form>
public function postTradeFinish(Request $request){
        $key = $request->key;
        return Session::get($key);
    }

Rymercyble started a new conversation Feedback For Shopping Cart Logic

Hello, I would appreciate feedback to logic behind my shopping cart. At /stage1 user fills data like name address etc. which i store as temporary session. Then I redirect him to /stage2 with key to that session. At /stage2 is payment wall. With JS I catch the key and store it locally then retrieve it and insert it to hidden input. After clicking "pay" I retrieve session in controller using key from hidden input to pair the user's data with payment.

Rymercyble left a reply on Using Data From Controller In Different Controller

@JLRDW - how to manage them when there will be for example 50 sessions existing at same time ? i need unique name for each session

Rymercyble left a reply on Using Data From Controller In Different Controller

@jlrdw how to manage them when there will be for example 50 sessions existing at same time ?

13 Mar
2 months ago

Rymercyble started a new conversation Using Data From Controller In Different Controller

hello, at /stage1 is post form via which I'm getting data which I need to store in db but not until confirmating via post form at /stage2

Route::post('/stage1', '[email protected]');
public function postTrade(Request $request){
        return redirect('/stage2')->with(['data' => $request->all()]);
    }
Route::get('/stage2', '[email protected]');
public function getTradeFinish(){
        $data = Session::has('data') ? Session::get('data') : [];
        return view('tradeFinish')->with(['data' => 'data']);
    }

to this point it works good but when I submit post at /stage2 it gives me 419 Page Expired

Route::post('/stage2', '[email protected]');
public function postTradeFinish(){
        return Session::has('data') ? Session::get('data') : [];
    }

any advice ?

02 Feb
3 months ago

Rymercyble left a reply on Using Boolean In Middleware

i made mistake in different place

Rymercyble started a new conversation Using Boolean In Middleware

hello i'm making middleware to control access based on users role

if(Sentinel::check()){
            if(Sentinel::getUser()->roles()->select('role_id')->first()->role_id >= 100){
                return $next($request);
            } else {
                return redirect()->back()->with(['error' => 'Access denied']);
            }
        } else {
            return redirect ('/login')->with(['error' => 'You are not logged in.']);
        }

but

Sentinel::getUser()->roles()->select('role_id')->first()->role_id >= 100

return boolean what results in exception The Response content must be a string or object implementing __toString(), "boolean" given.

is there a way to allow boolean in middleware or different way how to check this ?

18 Nov
6 months ago

Rymercyble started a new conversation Code Review

Hello, I would like to know if doing things like this is worth it. This check if conversation already exist and if no then I save it so i can show every conversation for each user without need of sending query to table with all messages and conversation ids they belongs to

if(Conversation::where('conversation_id', $new_chat_id)->first() != null){
            return redirect("/messages/{$new_chat_id}");
        } else {
            Conversation::insert([
                'conversation_id' => $new_chat_id,
                'user1' => $id,
                'user2' => $recipient
            ]);
            return redirect("/messages/{$new_chat_id}");
        }
22 Jun
11 months ago

Rymercyble started a new conversation How To Transform Number From 1 To 2^31-1 Into Hexadecimal Number Which Contains E.g. 15 Digits Evey Time

hello i'm working with laravel making something like social site,

users profiles are /users/id

i would like to hide user's ids behind something like hash but in hexadecimal form with every time same length

ideal would be if it cant be retrieved back to original number

yes i could just attach random number to each user but there would be every time check if that number isn't already attached to another user i tried $id_transform = hexdec( substr ( md5 ( md5 ( $id_transform )) , 10 , -10 )); but that doesn't create unique and same length strings

06 Apr
1 year ago

Rymercyble left a reply on Automatically Changing Query Based On Received Data

@arukomp how to change this

User::whereHas('languages', function($query){
                $query->where('name', Request::get('language'));
            })

to when(!empty... ? this relation is m:n with language_user pivot

Rymercyble left a reply on Automatically Changing Query Based On Received Data

@arukomp that will still start query even if request was empty or ?

05 Apr
1 year ago

Rymercyble started a new conversation Automatically Changing Query Based On Received Data

I want to make user filter search. For all users I can use

User::all();

And if i want to filter them by country I need

User::where('country', Country::where('name', $country)->select('id')->first()->id)

but this don't handle situation when user won't specify country so I need to change it to something like this

if (Request::get('country') == ''){
                $country_e = '!=';
                $country = 'default';
            } else {
                $country_e = '=';
            }

User::where('country', $country_e, Country::where('name', $country)->select('id')->first()->id)

This way i would have to use like 100 ifs to handle every combination

So how to make query where "where" would count only if data which each "where" search was received

04 Apr
1 year ago

Rymercyble started a new conversation 2 Different Pivots For 2 Tables

I have table users and table language and I want to make pivot for languages users know and don't know but want to learn them so I need pivots language_user and unknown_language_user but this don't work because query for unknown_language_user want to join unknown_language table which don't exist.

04 Feb
1 year ago

Rymercyble left a reply on How To Share Variable From One Method To Second

@topvillas did you mean something like this ?

private function getProfile($id){
        return User::where('hidden_id', $id)->first();
    }

    private function getInfo(){
        $profile = $this->getProfile();
        $id = $profile->id;
        return $info = [
            'physical_gender' => $profile->show_physical_gender == 1 ? User::find($id)->physicalGender()->select('name')->first() : null,
            'mental_gender' => $profile->show_mental_gender == 1 ? User::find($id)->mentalGender()->first() : null,
            'sexuality' => $profile->show_sexuality == 1 ? User::find($id)->sexuality()->first() : null,
            'smoking' => $profile->show_smoke == 1 ? User::find($id)->smoking()->first() : null,
            'alcohol' => $profile->show_alcohol == 1 ? User::find($id)->alcohol()->first() : null,
            'language_i_know' => $profile->show_language_i_know == 1 ? User::find($id)->languages()->select('name','level')->get() : null,
            'language_i_want_to_learn' => $profile->show_language_i_want_to_learn == 1 ? User::find($id)->unknownLanguages()->get() : null,
            'relationship_status' => $profile->show_relationship_status == 1 ? User::find($id)->relationship()->first() : null,
            'children_status' => $profile->show_children_status == 1 ? User::find($id)->children()->first() : null,
            'search_status' => $profile->show_search_status == 1 ? User::find($id)->search()->first() : null,
            'religion' => $profile->show_religion == 1 ? User::find($id)->religion()->first() : null,
            'country' => $profile->show_country == 1 ? User::find($id)->countries()->first() : null,
            'city' => $profile->show_city == 1 ? User::find($id)->city()->first() : null,
        ];
    }

    private function showProfile($id){
        $profile = $this->getProfile();
        $info = $this->getInfo();
        if (!$profile){
            return (['error', 'No such profile exist.']);
        }
        if(Sentinel::getUser()->id != $id){
            return view('profile', ['profile' => $profile, 'info' => $info, 'change' => '']);
        } elseif(Sentinel::getUser()->id == $id){
            return view('profile', ['profile' => $profile, 'info' => $info, 'change' => 'change']);
        }
    }

    public function changeProfile(Request $request){
        $profile = $this->getProfile();
        $info = $this->getInfo();
        if ($request->input('save') == 'Save'){
            $input = $request->all();
            if($input['nick_name'] != $profile->nick_name){
                $user = User::where('nick_name', $profile->nick_name)->first();
                $user->nick_name = $input['nick_name'];
                $user->save();
            }

            return redirect()->back()->with(['announcement', 'Your profile was updated.']);
        }
    }
02 Feb
1 year ago

Rymercyble started a new conversation How To Share Variable From One Method To Second

this is my controller

class profileController extends Controller
{
    public function showProfile(Request $request, $id){
        $profile = User::where('hidden_id', $id)->first();
        if (!$profile){
            return (['error', 'No such profile exist.']);
        }
        $id = $profile->id;
        $info = [
            'physical_gender' => $profile->show_physical_gender == 1 ? User::find($id)->physicalGender()->select('name')->first() : null,
            'mental_gender' => $profile->show_mental_gender == 1 ? User::find($id)->mentalGender()->first() : null,
            'sexuality' => $profile->show_sexuality == 1 ? User::find($id)->sexuality()->first() : null,
            'smoking' => $profile->show_smoke == 1 ? User::find($id)->smoking()->first() : null,
            'alcohol' => $profile->show_alcohol == 1 ? User::find($id)->alcohol()->first() : null,
            'language_i_know' => $profile->show_language_i_know == 1 ? User::find($id)->languages()->select('name','level')->get() : null,
            'language_i_want_to_learn' => $profile->show_language_i_want_to_learn == 1 ? User::find($id)->unknownLanguages()->get() : null,
            'relationship_status' => $profile->show_relationship_status == 1 ? User::find($id)->relationship()->first() : null,
            'children_status' => $profile->show_children_status == 1 ? User::find($id)->children()->first() : null,
            'search_status' => $profile->show_search_status == 1 ? User::find($id)->search()->first() : null,
            'religion' => $profile->show_religion == 1 ? User::find($id)->religion()->first() : null,
            'country' => $profile->show_country == 1 ? User::find($id)->countries()->first() : null,
            'city' => $profile->show_city == 1 ? User::find($id)->city()->first() : null,
        ];
        if(Sentinel::getUser()->id != $id){
            return view('profile', ['profile' => $profile, 'info' => $info, 'change' => '']);
        } elseif(Sentinel::getUser()->id == $id){
            return view('profile', ['profile' => $profile, 'info' => $info, 'change' => 'change']);
        }
    }

    public function changeProfile(Request $request){
        if ($request->input('save') == 'Save'){
            $input = $request->all();
            if($input['nick_name'] != $profile->nick_name){
                $user = User::where('nick_name', $profile->nick_name)->first();
                $user->nick_name = $input['nick_name'];
                $user->save();
            }

            return redirect()->back()->with(['announcement', 'Your profile was updated.']);
        }
    }
}

and i need to share $profile and $info to changeProfile method so i don't need to repeat query

Rymercyble left a reply on Am I On Good Way Or I Should Refactor ?

I have stored unique info about users in table users and other info (which many users have same like gender) in separated tables. In users table i have stored also info if user want to show his info on his profile thats why i have so many ifs in controller i can't do something like what @breki said because i have to check firstly if user want to show where he live and if not i don't need to start query to get his adress

18 Jan
1 year ago

Rymercyble started a new conversation Am I On Good Way Or I Should Refactor ?

my profile controller

public function showProfile(Request $request, $id){
        $profile = User::where('hidden_id', $id)->first();
        $id = $profile->id;

        if($profile->show_physical_gender == 1){
            $physical_gender = User::find($id)->physicalGender()->first();
        } else {
            $physical_gender = null;
        }
        if($profile->show_mental_gender == 1){
            $mental_gender = User::find($id)->mentalGender()->first();
        } else {
            $mental_gender = null;
        }
        if($profile->show_sexuality == 1){
            $sexuality = User::find($id)->sexuality()->first();
        } else {
            $sexuality = null;
        }
        if($profile->show_smoke == 1){
            $smoking = User::find($id)->smoking()->first();
        } else {
            $smoking = null;
        }
        if($profile->show_alcohol == 1){
            $alcohol = User::find($id)->alcohol()->first();
        } else {
            $alcohol = null;
        }
        if($profile->show_language_i_know == 1){
            $language_i_know = User::find($id)->languages()->select('name','level')->get();
        } else {
            $language_i_know = null;
        }
        if($profile->show_language_i_want_to_learn == 1){
            $language_i_want_to_learn = User::find($id)->unknownLanguages()->get();
        } else {
            $language_i_want_to_learn = null;
        }
        if($profile->show_relationship_status == 1){
            $relationship_status = User::find($id)->relationship()->first();
        } else {
            $relationship_status = null;
        }
        if($profile->show_children_status == 1){
            $children_status = User::find($id)->children()->first();
        } else {
            $children_status = null;
        }
        if($profile->show_search_status == 1){
            $search_status = User::find($id)->search()->first();
        } else {
            $search_status = null;
        }
        if($profile->show_religion == 1){
            $religion = User::find($id)->religion()->first();
        } else {
            $religion = null;
        }
        if($profile->show_country == 1){
            $country = User::find($id)->countries()->first();
        } else {
            $country = null;
        }
        if($profile->show_city == 1){
            $city = User::find($id)->city()->first();
        } else {
            $city = null;
        }
        $info = [
            'physical_gender' => $physical_gender,
            'mental_gender' => $mental_gender,
            'sexuality' => $sexuality,
            'smoking' => $smoking,
            'alcohol' => $alcohol,
            'language_i_know' => $language_i_know,
            'language_i_want_to_learn' => $language_i_want_to_learn,
            'relationship_status' => $relationship_status,
            'children_status' => $children_status,
            'search_status' => $search_status,
            'religion' => $religion,
            'country' => $country,
            'city' => $city,
        ];
        if(Sentinel::getUser()->id != $id){
            return view('profile', ['profile' => $profile, 'info' => $info, 'change' => '']);
        } elseif(Sentinel::getUser()->id == $id){
            if (Request::get('change') != 'Change'){
                return view('profile', ['profile' => $profile, 'info' => $info, 'change' => 'able']);
            } elseif (Request::get('change') == 'Change'){
                return view('profile', ['profile' => $profile, 'info' => $info, 'change' => 'change']);
            }
        }
    }

my view

if($change == 'able'){
        ?>
        <form action="" method="GET">
            <input type="submit" name="change"  value="Change">
        </form>
        <?php
    }
    if($change == 'change'){
        ?>
        <form action="" method="GET">
            <input type="submit" name="save"  value="Save changes">
        </form>
        <?php
    } else {
        if($profile->name_decision == 0){
            echo $profile->nick_name;
        } elseif($profile->name_decision == 1){
            echo $profile->first_name;
        } elseif($profile->name_decision == 2){
            echo $profile->first_name, $profile->last_name;
        }
        if($info['physical_gender'] != null){
            echo '</br>'.ucfirst($info['physical_gender']->name);
        }
        if($info['mental_gender'] != null){
            echo '</br>'.ucfirst($info['mental_gender']->name);
        }
        if($info['sexuality'] != null){
            echo '</br>'.ucfirst($info['sexuality']->name);
        }
        if($info['smoking'] != null){
            echo '</br>'.ucfirst($info['smoking']->name);
        }
        if($info['alcohol'] != null){
            echo '</br>'.ucfirst($info['alcohol']->name);
        }
        if($info['language_i_know'] != ""){
            foreach($info['language_i_know'] as $lang){
                echo '</br>'.ucfirst($lang->name).' '.$lang->level;
            }
        }
        if($info['language_i_want_to_learn'] != ""){
            foreach($info['language_i_want_to_learn'] as $lang2){
                echo '</br>'.ucfirst($lang2->name);
            }
        }
        if($info['relationship_status'] != null){
            echo '</br>'.ucfirst($info['relationship_status']->name);
        }
        if($info['search_status'] != null){
            echo '</br>'.ucfirst($info['search_status']->name);
        }
        if($info['religion'] != null){
            echo '</br>'.ucfirst($info['religion']->name);
        }
        if($info['country'] != null){
            echo '</br>'.ucfirst($info['country']->name);
            if($info['city'] != null){
                echo ' - '.ucfirst($info['city']->name);
            }
        }
    }
02 Jan
1 year ago

Rymercyble left a reply on Filter Users In M:N Database

@GertjanRoke i have one additional question - for languages i have 2 tables one for languages which user know and one for languages which user want to learn. how it would be in that case ?

Rymercyble left a reply on Filter Users In M:N Database

@GertjanRoke it returns me strpos() expects parameter 1 to be string, array given

Rymercyble left a reply on Filter Users In M:N Database

yes for example yes

Rymercyble started a new conversation Filter Users In M:N Database

I have users table with data like nickname, date of birth etc. Then I have tables like countries, country_user, languages, language_user. So I can get request like "find all users by age and country" or any combinations like this.

I have no idea how to make query for this. I'm not sure if it is good type of question for this forum but I've been searching at google for hours and nothing found.

23 Dec
1 year ago

Rymercyble started a new conversation Universal Middleware To Controll Content According To Roles

i want to do things like if you are admin and you look at user profile for you there will be option to ban that user or in chat room admin will have option to delete message of any user

i can make middleware like this

if($role == 'member'){
    return redirect('/people/profile/{id}');
 } else {
    return redirect('/people/profile/{id}')->with(['access' => 'admin']);
}

but this is solution only for one view so i need unique middleware for every view otherwise i can make role check in each view both options are bad

so exist any option how to make universal middleware for this ?

something what do same thing as this

if($role == 'member'){
    return $next($request);
 } else {
    return $next($request);->with(['access' => 'admin']);
}
20 Dec
1 year ago

Rymercyble left a reply on $next($request)->with();

i'm trying to make middleware to controll content based on roles

Rymercyble started a new conversation $next($request)->with();

this

return $next($request)->with(['access' => 'owner']);

throw BadMethodCallException Method with does not exist.

how i can do it ?

18 Dec
1 year ago

Rymercyble left a reply on Automatic Created Tables

@martinbean by this i wanted to avoid this

If there would be 1000 users and everyone will write to everyone e.g. 100 messages then i would like to have 499 500 tables instead of table with 49 950 000 messages which i will need read everytime when someone would want to read his messages

Rymercyble started a new conversation Automatic Created Tables

can be table created automatically ? i want to create table for every conversation between 2 users so i need something like this

$id1= 1;
$id2= 2;

$table_name = $id1."_".$id2;

php artisan:make migration $table_name

Schema::create($table_name, function (Blueprint $table) {
            $table->integer('id')->unsigned();
            $table->text('message');
        $table->timestamps();

            $table->engine = 'InnoDB';
        });

php artisan migrate

and delete that migration

but all automatically

21 Nov
1 year ago

Rymercyble started a new conversation @yield Don't Work

my web.php

Route::get('/', function () {
    return view('master');
});

in master.blade.php i call @yield('header') in header.blade.php @extends('master')

@section('header') (html) @endsection

yes I have started php i have both blade.php in views directory I tried make new laravel project but it didn't help

04 Nov
1 year ago

Rymercyble started a new conversation Select Everything Between X And Y

i use

DB::table('users')->whereBetween('date_of_birth', [$carbon_max, $carbon_min])->get();

if $carbon_max and $carbon_min was for example 10 and 1 this would return 9,8,7,6,5,4,3,2 but i also need 10 and 1

but this

$users = DB::table('users')
                ->where('date_of_birth', '>=', $carbon_min)
                ->where('date_of_birth', '<=', $carbon_max)
                ->get();

don't work for me

Rymercyble left a reply on Posting Data To View

solved by moving

return view('people', compact('users'));

inside if

Rymercyble left a reply on Posting Data To View

with

$users = [];

before if it don't give error but don't show any user by default

Rymercyble left a reply on Posting Data To View

i love this automatic formating of my post half is not shown...

Rymercyble started a new conversation Posting Data To View

my controller

public function people() { $min_age = Request::has('min_age') ? Request::get('min_age') : null; $max_age = Request::has('max_age') ? Request::get('max_age') : null;

    if (isset($min_age) && isset($max_age))
    {
        $carbon = Carbon::today();
        $carbon_max = Carbon::today();
        $year_min = $carbon->year - $min_age;
        $year_max = $carbon_max->year - $max_age;
        $month = $carbon->month;
        $day = $carbon->day;
        $carbon_min = $carbon->setDate($year_min, $month, $day)->toDateString();
        $carbon_max = $carbon_max->setDate($year_max, $month, $day)->toDateString();

        $users = Connection::whereBetween('date_of_birth', array($carbon_min, $carbon_max))->get();
    }

    return view('people', compact('users'));
}

my view

                <a href="/people/<?php echo $user->nick_name; ?> "><?php echo $user->nick_name; ?></a><br>
                <?php echo $user->first_name; ?>
                <?php echo $user->last_name; ?>
            </div>
        <?php } ?>

it gives

ErrorException Undefined variable: users in foreach in view