deladels

deladels

Member Since 2 Years Ago

Experience Points
5,180
Total
Experience

4,820 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
38
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 2
5,180 XP
Sep
28
3 weeks ago
Activity icon

Replied to How To Refactor My Code Using The DRY Priniciple

Alright Great, Thanks for the Help @afitriali

Sep
25
3 weeks ago
Activity icon

Replied to How To Refactor My Code Using The DRY Priniciple

Yes, I have managed to sample that out @afitriali. What I can't seem to figure out is the routing for each group.

Previously, I had it done like this, eg: www.example.com/group-name. Any help?

Sep
22
3 weeks ago
Activity icon

Replied to How To Refactor My Code Using The DRY Priniciple

Thank You. But the thing is, I don't want to be repeating code every time a new group has to be added.

Right now, before a new group is created, iI have to set up a new controller etc for the group.

Sep
20
4 weeks ago
Activity icon

Started a new Conversation How To Refactor My Code Using The DRY Priniciple

So I am Working on a project and I have gotten to a point where I have noticed I've been repeating myself. I learned about the DRY Principle after some research but can't seem to figure out how to implement it in my situation exactly. Any help will be appreciated.

So in my project, I have multiple "groups'. Now what I was doing is creating a resource controller for each fellowship (group-one, group-two, group-3). Now all these group controllers have similar functionalities (which defies the DRY Principle). They all access the same Member model (to create new members, edit a particular member, update a member as per the group). A group has many members and a member belongs to a group. Now I have multiple auth guards which made tying the guards to the specific group controllers easier so when a leader of the group logs in, I use middlewares to check the fellowship and redirect to the appropriate fellowship page

here are my code snippets:

Member Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Member extends Model
{
    protected $fillable = [
        
        'lastname', 'firstname', 'other_names', 'phone', 'alt_phone', 'gender', 'fellowship_id', 'address', 'department_id', 'email', 'dob', 'school', 'work'
    ];

    public function cell()
    {
        return $this->belongsTo(Cell::class);
    }

    public function fellowship()
    {
        return $this->belongsTo(Fellowship::class);
    }

    public function department()
    {
        return $this->belongsTo(Department::class);

    }

    public function setFirstNameAttribute($value)
    {
        $this->attributes['firstname'] = ucwords($value);
    }

    public function setLastNameAttribute($value)
    {
        $this->attributes['lastname'] = ucfirst($value);
    }

    public function setOtherNamesAttribute($value)
    {
        $this->attributes['other_names'] = ucwords($value);
    }
}

Group 1 Controller

<?php

namespace App\Http\Controllers;

use Excel;

use Illuminate\Http\Request;

use App\Member;

use App\Fellowship;

use App\Department;

use Carbon\Carbon;

use Charts;

use App\Exports\DunamisExport;

use App\Metrics\DunamisMetrics;

use Illuminate\Http\Response;

class DunamisController extends Controller
{
    public function __construct(DunamisMetrics $metrics)
    {
        $this->middleware('auth:leader');

        $this->middleware('Dunamis'); //checks if the group leader trying to access the dashboard is in  the "Dunamis" group.

        $this->metrics = $metrics;
    }

    public function getFellowship()
    {
        $fellowship = Fellowship::where('name', 'Dunamis')->first();

        return $fellowship;
    }

 
    public function index()
    {
        $fellowship = $this->getFellowship();

        $currentMonthMemberMetrics = $this->metrics->totalMembersAddedCurrentMonth();

        $monthlyMemberMetrics = round($this->metrics->percentage());

        $members = $fellowship->members()->get();

        $totalMembers = $members->count();

        $totalCells = $fellowship->cells->count();

        $maleMembers = $fellowship->members()->whereGender('Male')->count();

        $femaleMembers = $fellowship->members()->whereGender('Female')->count();

        $genderChart = Charts::create('donut', 'highcharts')
                                ->title('Gender Ratio')
                                ->elementLabel("Gender Allocation")
                                ->labels(['Males', 'Females'])
                                ->values([$maleMembers, $femaleMembers])
                                ->width(0)
                                ->height(250)
                                ->responsive(false)
                                ->colors(['#f14715','#a62728']);

        $chart = Charts::database($members, 'area', 'highcharts')
                                ->title('Members')
                                ->elementLabel("Total Members Per Month")
                                ->width(0)
                                ->responsive(false)
                                ->colors(['#F12711'])
                                ->lastByMonth();


        return view('fellowship.dunamis.index', compact('currentMonthMemberMetrics','monthlyMemberMetrics','chart', 'genderChart' ,'members', 'totalMembers', 'totalCells'));
    }

  
    public function create()
    {
        $fellowship = $this->getFellowship();

        $departments = Department::all();

        return view('fellowship.dunamis.create', compact('departments', 'fellowship'));
    }

   
    public function store(Request $request)
    {
        $this->validate($request, [

            'lastname'      =>  'required',
            'firstname'     =>  'required',
            'phone'         =>  'required',
            'gender'        =>  'required',
            'fellowship'    =>  'required',
            'address'       =>  'required',
            'dob'           =>  'required',
            'email'         =>  'required',

        ]);

        $member = Member::create([

            'lastname'      =>  request('lastname'),
            'firstname'     =>  request('firstname'),
            'other_names'   =>  request('other_names'),
            'phone'         =>  request('phone'),
            'alt_phone'     =>  request('alt_phone'),
            'address'       =>  request('address'),
            'gender'        =>  request('gender'),
            'fellowship_id' =>  request('fellowship'),
            'department_id' =>  request('department'),
            'email'         =>  request('email'),
            'school'        =>  request('school'),
            'work'          =>  request('work'),
            'dob'           =>  Carbon::parse(request('dob'))->format('Y-m-d')
        ]);

        if ($member->save()) {
            # code...
            $request->session()->flash('success', 'You Successfully Added A New  Member!');

            return redirect()->route('dunamis.index');
        } else {

            $request->session()->flash('unsucccessful', 'Something Went Wrong. Check Your Inputs And Try Again');

            return redirect()->back()->withInput();
        }
    }


    public function show($id)
    {
        $member = Member::find($id);

        return view('fellowship.dunamis.show', compact('member'));
    }

   
    public function edit($id)
    {
        $member = Member::find($id);

        $departments = Department::all();

        $fellowship  =  $this->getFellowship();

        return view('fellowship.dunamis.edit', compact('member', 'departments', 'fellowship'));
    }

  
    public function update(Request $request, $id)
    {
        $this->validate($request, [

            'lastname'      =>  'required',
            'firstname'     =>  'required',
            'phone'         =>  'required',
            'gender'        =>  'required',
            'fellowship'    =>  'required',
            'address'       =>  'required',
            'dob'           =>  'required',
            'email'         =>  'required',
        ]);

        $dunamisMember = Member::find($id);

        $dunamisMember->lastname      = $request->get('lastname');
        $dunamisMember->firstname     = $request->get('firstname');
        $dunamisMember->other_names   = $request->get('other_names');
        $dunamisMember->phone         = $request->get('phone');
        $dunamisMember->alt_phone     = $request->get('alt_phone');
        $dunamisMember->address       = $request->get('address');
        $dunamisMember->dob           = Carbon::parse(request('dob'))->format('Y-m-d');
        $dunamisMember->gender        = $request->get('gender');
        $dunamisMember->fellowship_id = $request->get('fellowship');
        $dunamisMember->department_id = $request->get('department');
        $dunamisMember->email         = $request->get('email');
        $dunamisMember->school        = $request->get('school');
        $dunamisMember->work          = $request->get('work');


        if ($dunamisMember->save()) {
            # code...
            $request->session()->flash('successful', 'You Successfully Edited Member Details');

            return redirect()->route('dunamis.index');
        } else {

            $request->session()->flash('unsuccessful', 'Something Went Wrong. Check Your Inputs And Try Again');

            return redirect()->back()->withInput();
        }
    }


    public function exportToExcel()
    {
        return Excel::download(new DunamisExport, 'dunamis_members.xlsx');
    }

    public function members()
    {
        $fellowship = $this->getFellowship();

        $members = $fellowship->members()->get();

        $totalMembers = $members->count();

        return view('fellowship.dunamis.members', compact('members', 'totalMembers'));
    }

}

Group Two Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Member;

use App\Fellowship;

use App\Department;

use Carbon\Carbon;

use ConsoleTVs\Charts\Facades\Charts;

use App\Exports\ChosenExport;

use App\Metrics\ChosenMetrics;

use Excel;

use Illuminate\Validation\ValidationException;

class ChosenController extends Controller
{

    public function __construct(ChosenMetrics $metrics)
    {
        $this->middleware('auth:leader');

        $this->middleware('Chosen');

        $this->metrics = $metrics;
    }

    public function getFellowship()
    {
        $fellowship = Fellowship::whereName('Chosen')->first();

        return $fellowship;
    }


    public function index()
    {
        $currentMonthMemberMetrics = $this->metrics->totalMembersAddedCurrentMonth();

        $monthlyMemberMetrics = round($this->metrics->percentage());

        $fellowship = $this->getFellowship();

        $members = $fellowship->members()->get();

        $totalMembers = $members->count();

        $totalCells = $fellowship->cells->count();

        $maleMembers = $fellowship->members()->whereGender('Male')->count();

        $femaleMembers = $fellowship->members()->whereGender('Female')->count();

        $genderChart = Charts::create('donut', 'highcharts')
                                ->title('Gender Ratio')
                                ->elementLabel("Gender Allocation")
                                ->labels(['Males', 'Females'])
                                ->values([$maleMembers, $femaleMembers])
                                ->width(0)
                                ->height(250)
                                ->responsive(false)
                                ->colors(['#f14715','#a62728']);

        $chart = Charts::database($members, 'area', 'highcharts')
                                ->title('Members')
                                ->elementLabel("Total Members Per Month")
                                ->width(0)
                                ->responsive(false)
                                ->colors(['#F12711'])
                                ->lastByMonth();


        return view('fellowship.chosen.index', compact('currentMonthMemberMetrics','monthlyMemberMetrics','totalCells', 'chart', 'genderChart', 'members', 'totalMembers'));
    }

 
    public function create()
    {
        $fellowship = $this->getFellowship();

        $departments = Department::all();

        return view('fellowship.chosen.create', compact('departments', 'fellowship'));
    }


    public function store(Request $request)
    {
            $this->validate($request, [

                'lastname'      =>  'required',
                'firstname'     =>  'required',
                'phone'         =>  'required',
                'gender'        =>  'required',
                'fellowship'    =>  'required',
                'address'       =>  'required',
                'dob'           =>  'required',
                'email'         =>  'required',

            ]);

            $member = Member::create([

                'lastname'      =>  request('lastname'),
                'firstname'     =>  request('firstname'),
                'other_names'   =>  request('other_names'),
                'phone'         =>  request('phone'),
                'alt_phone'     =>  request('alt_phone'),
                'address'       =>  request('address'),
                'gender'        =>  request('gender'),
                'fellowship_id' =>  request('fellowship'),
                'department_id' =>  request('department'),
                'email'         =>  request('email'),
                'school'        =>  request('school'),
                'work'          =>  request('work'),
                'dob'           =>  Carbon::parse(request('dob'))->format('Y-m-d')
            ]);

            if ($member->save()) {
                # code...
                $request->session()->flash('success', 'You Successfully Added A New  Member!');

                return redirect()->route('chosen.index');
            } else {

                $request->session()->flash('unsuccessful', 'Something Went Wrong. Check Your Inputs And Try Again');

                return redirect()->back()->withInput();
            }

    }

 
    public function show($id)
    {
        $member = Member::find($id);

        return view('fellowship.chosen.show', compact('member'));
    }


    public function edit($id)
    {
        $member = Member::find($id);

        $departments = Department::all();

        $fellowship  =  $this->getFellowship();

        return view('fellowship.chosen.edit', compact('member', 'departments', 'fellowship'));
    }

 
    public function update(Request $request, $id)
    {
        $this->validate($request, [

                'lastname'      =>  'required',
                'firstname'     =>  'required',
                'phone'         =>  'required',
                'gender'        =>  'required',
                'fellowship'    =>  'required',
                'address'       =>  'required',
                'dob'           =>  'required',
                'email'         =>  'required',
        ]);

        $chosenMember = Member::find($id);

        $chosenMember->lastname      = $request->get('lastname');
        $chosenMember->firstname     = $request->get('firstname');
        $chosenMember->other_names   = $request->get('other_names');
        $chosenMember->phone         = $request->get('phone');
        $chosenMember->alt_phone     = $request->get('alt_phone');
        $chosenMember->address       = $request->get('address');
        $chosenMember->dob           = Carbon::parse(request('dob'))->format('Y-m-d');
        $chosenMember->gender        = $request->get('gender');
        $chosenMember->fellowship_id = $request->get('fellowship');
        $chosenMember->department_id = $request->get('department');
        $chosenMember->email         = $request->get('email');
        $chosenMember->school        = $request->get('school');
        $chosenMember->work          = $request->get('work');


        if ($chosenMember->save()) {
            # code...
            $request->session()->flash('successful', 'You Successfully Edited Member Details');

            return redirect()->route('chosen.index');
        }else{

            $request->session()->flash('unsuccessful', 'Something Went Wrong. Check Your Inputs And Try Again');

            return redirect()->back()->withInput();
        }
    }


    public function exportToExcel()
    {
        return Excel::download(new ChosenExport, 'chosen_members.xlsx');
    }

    /**
     * Display a list of all members
     */
    public function members()
    {
        $fellowship = $this->getFellowship();

        $members = $fellowship->members()->get();

        $totalMembers = $members->count();

        return view('fellowship.chosen.members', compact('members', 'totalMembers'));
    }
}

I have 7 other groups, so you can imagine, this also isn't scalable and will be difficult to maintain since if there's a new group, I'll have to code for that.

Thanks for your help.

Jan
23
1 year ago
Activity icon

Replied to Laravel 5.5 Redirect After Logout

@Snapey yes i do have the standard Auth::route(). i also have a single logout route.

thanks for the tip tho.

Jan
22
1 year ago
Activity icon

Started a new Conversation Laravel 5.5 Redirect After Logout

i am trying to redirect the user to the login page after they click the logout link but this does not seem to work (used to work at first). i have tried many of the solutions here and online but still.

web.php

Route::get('logout', '\App\Http\Controllers\Auth\[email protected]');

LoginController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Auth;
use Illuminate\Http\Request;

class LoginController extends Controller
{


    use AuthenticatesUsers;

    protected $redirectTo = '/home';


    public function __construct()
    {
        $this->middleware('guest')->except('logout');

         // $this->middleware('guest', ['except' => ['logout', 'logout']]);
    }

    public function logout(Request $request){
        Auth::logout();
        return redirect('/login');
    }
}

nav.blade.php

      <ul class="right hide-on-med-and-down center-align">
        <li><a href="/">HOME</a></li>
        <li><a href="{{ route('logout') }}">LOGOUT</a></li>
      </ul>

Jan
16
1 year ago
Activity icon

Replied to Issue Using Mailable And Markdowns

@Snapey thanks so much for your help. it works just fine. :)

Activity icon

Replied to Issue Using Mailable And Markdowns

@Snapey how do you suggest i go about it?

BookingsController.php

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controllers;

use Illuminate\Http\Request;

use Braintree_Transaction;

use App\Booking;

use App\Schedule;

use Session;

use Mail;

use App\Mail\ScheduleBooked;

class BookingsController extends Controller
{ 

    public function store(Schedule $schedule, Request $request){

        $this->validate( request(), [

            'lastName'        => 'required',
            'firstName'       => 'required',
            'email'           => 'required',
            'mobilenumber'    => 'required',
            'additionalId'    => 'required|max:13',
            'idNumber'        => 'required'

        ]);

        Booking::create([

            'schedule_id'   => $schedule->id,
            'lastname'      => request('lastName'),
            'firstname'     => request('firstName'),
            'email'         => request('email'),
            'mobilenumber'  => request('mobilenumber'),
            'id_type'       => request('additionalId'),
            'id_number'     => request('idNumber')

        ]);

        $result = Braintree_Transaction::sale([
                      'amount' => $schedule->price,
                      'paymentMethodNonce' => $request->payment_method_nonce,
                      'customer' => [
                        'firstName'  => $request->firstName,
                        'lastName'   => $request->lastName,
                        'phone'      => $request->mobilenumber,
                        'email'      => $request->email
                      ],
                      'options' => [
                        'submitForSettlement' => true,
                      ]
        ]);

        //Mail::to($request->email)->send(new ScheduleBooked);

        if (!$result->success) {

            \Session::flash('flash_message', 'Your Booking was not Successfull, please try again or contact us for help');
            
            return redirect('uschedule/{schedule}');
        }
        
        \Session::flash('flash_message', 'Your Booking has been Successfull');

        return redirect('uschedules');
    }    



    public function email(Request $request, $bookingId){

        $booking = Booking::find($bookingId);

        Mail::to($request->email)->send(new ScheduleBooked($booking));

        return redirect('/uschedules');
    }
}

Jan
15
1 year ago
Activity icon

Replied to Issue Using Mailable And Markdowns

It'll be hit when the user clicks on the submit/book button

The method is called within the bookingcontroller class.

Activity icon

Replied to Issue Using Mailable And Markdowns

So you are not calling the email route? yeah. looks like i am not hitting/calling it.

Activity icon

Replied to Issue Using Mailable And Markdowns

and yes $request->email contains and email address

Activity icon

Replied to Issue Using Mailable And Markdowns

@Snapey i actually did that. nothing is dumped. but like i said. putting the using the Mail facade directly in the store function sends an email.

Activity icon

Replied to Issue Using Mailable And Markdowns

@bobbybouwmann yes i am. i configured everything. crosschecked it. i realised that when i i place or do this Mail::to($request->email)->send(new ScheduleBooked()); within the store function of the BookingsController it fires the email.

2.No please. i have nothing on queues set up at the moment.

Activity icon

Started a new Conversation Issue Using Mailable And Markdowns

i am trying to send an email when a users books a schedule. (i want to use the simple way so this is triggered when a button is clicked)

BookingController.php

    public function email(Request $request, $bookingId){

        $booking = Booking::find($bookingId);

        Mail::to($request->email)->send(new ScheduleBooked($booking));

        return redirect('uschedules');
    }

ScheduleBooked.php (Mailable)

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Booking;

class ScheduleBooked extends Mailable
{
    use Queueable, SerializesModels;


    public $booking;



    public function __construct(Booking $booking)
    {
        $this->booking = $booking;
    }

    public function build()
    {
        return $this->markdown('emails.schedules.booked')->with([

                        'lastname'  => $this->booking->lastName,
                        'firstname' => $this->booking->firstName,
        ]);
    }
}

route file.

Route::get('/email', '[email protected]')->name('sendEmail');

i don't get any errors but the emails aren't being sent to my mailtrap.

Jan
12
1 year ago
Activity icon

Replied to Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message Error

@bestmomo yes i do.

edit.blade.php

<form class="col 12" method="POST" style="padding-top: 20px;">
    {{ csrf_field() }}
    {{ method_field('PUT') }}
    
    <div class="container">
        <div class="row">
            <div class="input-field col s6">
                <input class="validate" type="text" name="busRegNo" value="{{ $adminBus->reg_number }}"></input>
                <label><b>Registration Number</b></label>
            </div>
            <div class="input-field col s6">
                <input class="validate" type="text" name="busModel" value="{{ $adminBus->model }}"></input>
                <label><b>Model</b></label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s6">
                <input class="validate" name="capacity" type="number" value="{{ $adminBus->capacity }}"></input>
                <label for=""><b>Capcity</b></label>
            </div>
            <div class="input-field col s6">
                
            </div>
        </div>
        <div class="row">
            <div class="col offset-m2 m4">
                  <button class=" red darken-1 btn waves-effect waves-light" type="submit">SUBMIT<i class="material-icons right">send</i>
                  </button>
            </div>
         </div>
    </div>
        </div>
    </div>
</form>

create.blade.php


<form class="col 12" method="POST" action="">
    {{ csrf_field() }}
    <div class="container">
        <h5 class="center-align">Add A New Bus</h5>
        <div class="row">
            <div class="input-field col s6">
                <input class="validate" type="text" name="busRegNo"></input>
                <label><b>Registration Number</b></label>
            </div>
            <div class="input-field col s6">
                <input class="validate" type="text" name="busModel"></input>
                <label><b>Model</b></label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s6">
                <input class="validate" name="capacity" type="number"></input>
                <label for=""><b>Capacity</b></label>
            </div>
            <div class="input-field col s6">
                
            </div>
        </div>
        <div class="row">
            <div class="col offset-m2 m4">
                  <button class=" red darken-1 btn waves-effect waves-light" type="submit">SUBMIT<i class="material-icons right">send</i>
                  </button>
            </div>
         </div>
    </div>
        </div>
    </div>
</form>

``
Activity icon

Started a new Conversation Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message Error

so i am trying to build a crude system. the index method works or more like all the get methods/verbs work. but anytime i try to submit a form or edit an entry i get the above error.

namespace App\Http\Controllers;

use App\AdminBus;

use Illuminate\Http\Request;

class AdminBusController extends Controller
{

    //function/action to get all buses in the db
    public function index(AdminBus $addbus)
    {
        $addbus = AdminBus::all();

        return view('admin.addbus.index', compact('addbus'));
    }


    //function/action to create a new bus
    public function create()
    {
        return view('admin.addbus.create');
    }

    public function store(Request $request)
    {
       $this->validate( request(), [

            'busRegNo'  => 'required',
            'busModel'  => 'required',
            'capacity'  => 'required'

        ]);

        AdminBus::create([

        'reg_number'  => request('busRegNo'),
        'model'       => request('busModel'),
        'capacity'    => request('capacity')

    ]);
            Session::flash('message', 'Successfully created nerd!');
            return Redirect::to('bus'); 
    }

    
    public function show($adminBus)
    {
        $adminBus = AdminBus::find($adminBus);

        return view('admin.addbus.show', compact('adminBus'));
    }

  
    public function edit($adminBus)
    {
        $adminBus = AdminBus::find($adminBus);

        return view('admin.addbus.edit', compact('adminBus'));
    }


    public function update(Request $request, AdminBus $adminBus)
    {
        $adminBus = AdminBus::find($adminBus);

       $this->validate( request(), [

            'busRegNo'  => 'required',
            'busModel'  => 'required',
            'capacity'  => 'required'

        ]);
       
        $adminBus->reg_number = $request->get('reg_number');
        $adminBus->model      = $request->get('model');
        $adminBus->capacity   = $request->get('capacity');
        $adminBus->save();

            Session::flash('message', 'Successfully created nerd!');
            return Redirect::to('bus');
    }

web.php file

Route::resource('bus', 'AdminBusController');

any help?

Jan
10
1 year ago
Activity icon

Replied to Is It Possible To Pass Variables Like This

lol seriously guys?

people say this a lot about guys who are good developers.

this might not be an excuse but i am just a student who was asked to use laravel for his project work. i am very much new to this. anyway thanks @tykus .

i have figured it out.

Activity icon

Replied to Is It Possible To Pass Variables Like This

'[email protected]' shows all schedules.

the second one. the uri is to redirect users to that page after a successful login I'm using that to redirect based on the account type in my adminlogin controller. so if the account is a user he is sent to the schedules page but if its an admin he is sent to the dashboard.

Activity icon

Replied to Is It Possible To Pass Variables Like This

very much understood. any suggestions?

Activity icon

Replied to Is It Possible To Pass Variables Like This

UPDATED

Route::get('/schedules', '[email protected]'); was duplicated during copy and paste

so i have another route like that being accessed by another controller. could that be the error?

my route file


Route::get('/schedules', '[email protected]');

Route::get('schedule/{schedule}', '[email protected]');


Route::get('/braintree/token','[email protected]');

Route::post('/login/custom', [
    'uses' => '[email protected]',
    'as'   => 'login.custom'
]);
Route::group(['middleware' => 'auth'], function() {

Route::get('schedules', function() {
    dd(__FILE__);

});


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

});

Activity icon

Replied to Is It Possible To Pass Variables Like This

so i have another route like that being accessed by another controller. could that be the error?

my route file


Route::get('/schedules', '[email protected]');

Route::get('schedule/{schedule}', '[email protected]');

Route::get('/schedules', '[email protected]');

Route::get('/braintree/token','[email protected]');

Route::post('/login/custom', [
    'uses' => '[email protected]',
    'as'   => 'login.custom'
]);
Route::group(['middleware' => 'auth'], function() {

Route::get('schedules', function() {
    dd(__FILE__);

});


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

});

Activity icon

Replied to Is It Possible To Pass Variables Like This

yes @jorpedito . but there are records in there. a lot.

Route::get('schedules', function() {
    $schedules = App\Schedule::all(); // or whatever your query is...

   dd($schedules);

    return view('schedules', compact('schedules'));
});

same error for this dd isnt working.

Activity icon

Replied to Is It Possible To Pass Variables Like This

yes not working with the same error as before.

tried this: not working.

Route::get('schedules', function() {
    $schedules = App\Schedule::all(); // or whatever your query is...
    return view('schedules', compact('schedules'));
});

i am trying to route a user the schedules page which will display all scheduled in the database. i have a loop in the blade file with the $schedules variable. that's where the error is coming form.

    <table class="striped center responsive-table">
        <thead>
                <th>FROM</th>
                <th>TO</th>
                <th>DEPARTURE DATE</th>
                <th>DEPARTURE TIME</th>
                <th>BUS NO.</th>
                <th>PRICE</th>              
        </thead>
        <tbody>
            @foreach ($schedules as $schedule)
                <tr>
                    <td>{{ $schedule->departure_location }}</td>
                    <td>{{ $schedule->destination_location }}</td>
                    <td>{{ \Carbon\Carbon::parse($schedule->departure_date)->format('M d Y') }}</td>
                    <td>{{ date("h:i a", strtotime($schedule->departure_time)) }}</td>
                    <td>{{ $schedule->bus}}</td>
                    <td>{{ $schedule->price}}</td>
                    <td> <a href="schedule/{{$schedule->id }}" class="btn waves-effect red darken-1">BOOK</a> </td>
                </tr>
            @endforeach
        </tbody>
    </table>
Activity icon

Replied to Is It Possible To Pass Variables Like This

so all 4 alternatives are not working unfortunately

Activity icon

Replied to Is It Possible To Pass Variables Like This

i just did.

i get this error when trying to view the schedules.blade.php file.

Undefined variable: schedules (View: C:\xampp\htdocs\BusTravel\resources\views\schedules.blade.php)

Activity icon

Started a new Conversation Is It Possible To Pass Variables Like This

    Route::get('schedules', function(App\Schedule $schedules) {
        return view('schedules')->with($schedules);
    });

is this possible?

Activity icon

Replied to Route Not Redirecting

not working @bipin

Activity icon

Replied to Route Not Redirecting

@bipin still not working

Activity icon

Replied to Route Not Redirecting

@bipin i dont really get where you want me to put the first block of code. And the second one did not work. Still redirecting to the adminlogin page

Activity icon

Replied to Route Not Redirecting

tried yours @tisuchi did not work.

tried yours too @Ishatanjeeb. it keeps redirecting back to the login page

Jan
09
1 year ago
Activity icon

Started a new Conversation Route Not Redirecting

when i enter the email and password, i dont get redirected to the dashboard. i can not seem to figure out what is happening.

route.php file

Route::prefix('admin')->group(function(){
Route::get('/login', 'Auth\[email protected]')->name('admin.login');
Route::post('/login', 'Auth\[email protected]')->name('admin.login.submit');
Route::get('/', '[email protected]')->name('admin.dashboard');
});

AdminController.php

class AdminController extends Controller
{
   
    public function __construct()
    {
        $this->middleware('auth:admin');
    }

  
    public function index()
    {
        return view('admin');
    }
}

AdminLoginController.php

class AdminLoginController extends Controller
{
    public function __construct(){

        $this->middleware('guest:admin');
    }

    public function showLoginForm(){

        return view('auth/admin-login');
    }

    public function login(Request $request){

        //validate the form input data
        $this->validate( request(), [
            'email' => 'required',
            'password' => 'required'

        ]);


        if(Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)){

            return redirect()->intended(route('admin.dashboard'));

        }else{

            return redirect()->back()->withInput($request->only('email', 'remember'));

            }
        }
        
}

Admin.php (model)

class Admin extends Authenticatable
{
    use Notifiable;

    protected $guard = 'admin';


    protected $fillable = [
        'name','email', 'password',
    ];

 
    protected $hidden = [
        'password', 'remember_token',
    ];
}

Activity icon

Replied to Suggestion On Rerouting Users To Loginpage And Rerouting Back To Their Previous Page.

is it possible to do something like this?

<input class="validate" type="text" name="lastName" placeholder="Enter Last Name" value="{{ Session::get('lastName') }}">

Jan
08
1 year ago
Activity icon

Replied to Suggestion On Rerouting Users To Loginpage And Rerouting Back To Their Previous Page.

oh okay. that will mean i have to manually put the values into the session.cuz when i do a dd() i get null atm.

Activity icon

Started a new Conversation Suggestion On Rerouting Users To Loginpage And Rerouting Back To Their Previous Page.

so while working on my final year project, i decided to allow the users to browse through the up without having to be logged in since theres's this thing in UX/UI that says forcing users to login before viewing anything on an app is a deterrent.

so i am asking for you options on how to allow the user to browse through till where they'll have to make a booking or lets say till they get to the checkout page for example. now before they click on the place order button, i want to redirect them to login or register page and then sending them back to the order page.

any suggestions will be grateful.

Jan
07
1 year ago
Activity icon

Replied to Is It Possible To Pass The Same Uri To 2 Different Methods Ina Single Controller

yeah i realised that. from bottom up i guess. @tykus any suggestions on how to go about this?

Activity icon

Started a new Conversation Is It Possible To Pass The Same Uri To 2 Different Methods Ina Single Controller

route file:

Route::post('schedule/{schedule}', '[email protected]')->name('book.pay');

Route::post('schedule/{schedule}', '[email protected]')->name('book.store');

blade file:

{{ content goes here }}
Jan
06
1 year ago
Activity icon

Replied to Extracting Values From Url And Updating Table In Db

@Drfraker thanks very much. this worked flawlessly.

Activity icon

Replied to Passing Data From Blade To Controller

hi , i know this may be old but i find myself having a similar issue and i want to ask a question.

after getting the parameters, is there any where of passing the parameter to your model to be inserted into a table or use the parameter in a controller to update a row in the database? thank you.

Activity icon

Started a new Conversation Extracting Values From Url And Updating Table In Db

so using route model binding i am able to get this url : http://127.0.0.1:8000/schedule/1 is there anyway i can extract the id which in this case is one and insert it into a table in a database?

as at now this is what i have which is not working:

class BookingsController extends Controller {

//NB: i am passing/getting $schedule from the url, sort of
    public function getScheduleId($schedule){

        $booking = new Booking;

        $booking->schedule_id = $schedule;

        $booking->save();

}

public function store(){

    $this->validate( request(), [

            'lastName'      => 'required',
        'firstName'     => 'required',
        'email'         => 'required',
        'mobilenumber'  => 'required',
        'additionalId'  => 'required',
        'idNumber'      => 'required'

    ]);

    Booking::create([

        'schedule_id'           => request($schedule),
        'lastname'      => request('lastName'),
        'firstname'     => request('firstName'),
        'email'         => request('email'),
        'mobilenumber'  => request('mobilenumber'),
        'id_type'           => request('additionalId'),
        'id_number'     => request('idNumber')


    ]);
    
}

}

Jan
05
1 year ago
Activity icon

Replied to Accesing Values From Another Model

so like you said @bobbybouwmann i have set up the relationships. now, i want to pass the From: Accra value and To values along with the other inputs to my bookings controller in order to insert into my bookings table. how do i do that?

or better still how do i get the id or that specific schedule and pass it to be updated as a foreign key field.(NB: i have set up the relationships already)

Jan
04
1 year ago
Activity icon

Replied to Accesing Values From Another Model

Alright i'd do that. Thanks very much @bobbybouwmann

Activity icon

Replied to Accesing Values From Another Model

how do i connect them? through relationships?

so a user is able to book a particular schedule. i want to update the bookings table with the particular schedule the users book i"ll then like to display the respective values of booking on the payment iew page.

i dont know if i am making myself clear tho. THanks

Activity icon

Started a new Conversation Accesing Values From Another Model

i am trying to access values that reside in a controller within another controller. i used route model binding to route to specific schedule.

now i want to retrieve the schedule id or the schedule parameters in a bookingsController. how do i go about it?

this is how the page looks like https://imgur.com/a/Yy42d

my bookingscontroller.php

namespace App\Http\Controllers;

use App\Http\Controllers\Controllers;

use Illuminate\Http\Request;

use App\Booking;

use App\Schedule;

class BookingsController extends Controller {

public function store(){

    $schedule = new Schedule;

    $schedule = Schedule::find($id);

    $this->validate( request(), [

        'lastName'      => 'required',
        'firstName'     => 'required',
        'email'         => 'required',
        'mobilenumber'  => 'required',
        'additionalId'  => 'required',
        'idNumber'      => 'required'

    ]);
    dd(request()->all());
    dd(request($schedule->departure_location));

}

}

Jan
03
1 year ago
Activity icon

Replied to Suggestions On A How To Carry Out A Particular Task.

thank you so much @xmarks for your beautiful insights. @shez1983 thank you too. I'll try and see if i can add that. higher score is definitely a go for

Dec
29
1 year ago
Activity icon

Replied to Suggestions On A How To Carry Out A Particular Task.

maybe not necessary. just trying to make it more fancy and flexible. the logic is what i am trying to figure out.

the bus service is from one destination to another, kind of traveling distance. it doesnt go around town.

Dec
28
1 year ago
Activity icon

Started a new Conversation Suggestions On A How To Carry Out A Particular Task.

so i am working on a bus reservation system for my final year project in school. its not so huge.

now i am kinda caught up in a situation. i will want to allow users to select or book a particular seat in a bus, preferable via a select/drop down. is this advisable? if yes, i have been trying to sketch things but i cant seem to figure out how to go about it. any suggestions please?

Dec
23
1 year ago
Activity icon

Started a new Conversation Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message

i am trying to post data to my database. on submission of the form i get the error and i can seem to figure it out:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message

this is my route:

Route::post('/addBus', '[email protected]');

my model:

namespace App;

use Illuminate\Database\Eloquent\Model;

class AddBus extends Model {

protected $fillable = [ 'reg_number', 'model', 'capacity' ];

}

controller:

namespace App\Http\Controllers;

use App\Http\Controllers\Controllers;

use Illuminate\Http\Request;

use App\AddBus;

class BusesController extends Controller { //metthod to store buses public function store(){

    $this->validate( request(), [

        'busRegNo'  => 'required',
        'busModel'  => 'required',
        'capacity'  => 'required'

    ]);

    dd(request()->all());

    AddBus::create([

    'reg_number'  => request('busRegNo'),
    'model'       => request('busModel'),
    'capacity'    => request('capacity')

]);

return back();
}

}

Dec
22
1 year ago
Activity icon

Replied to Trying To Get Property Of Non-object

oh okay. thank you very much @tykus for your vivid explanation since i am new to laravel. and it worked perfectly.