curtiplas

Experience

5,030

0 Best Reply Awards

  • Member Since 4 Months Ago
  • 47 Lessons Completed
  • 0 Favorites

8th September, 2017

curtiplas left a reply on Handling No Results On [email protected] Method • 3 months ago

I ended up doing this in my controller

    public function show($email){
            return view('waitlist.show',['waitlist' => WaitList::where(compact('email'))->first()]);
        }

then just running an if($waitlist) on my blade to display one visual or another.

Thank you all!

curtiplas left a reply on Handling No Results On [email protected] Method • 3 months ago

Thank you everyone for the responses!

@sutherland using a 404 won't work for me as I don't want to return a 404 for this page; where I would want to return a 404 on other non-existent pages.

@Snapey I tried the snippet you posted in my WaitListController, but the results are the same. I'm not entirely sure what it's doing to be honest.

This is what I tried:

    public function show(WaitList $waitlist=null){

        return view('waitlist.show', compact('waitlist'));
    }

I might try the Exception handler method that @sutherland posted, if that doesn't work or proves to difficult I'll probably just get rid of the Route model binding and lookup the inside the show method.

7th September, 2017

curtiplas left a reply on Handling No Results On [email protected] Method • 3 months ago

@tisuchi @Norris sorry forgot to mention that I'm using a getKeyRoute to pass the email address in the url.

Also If I understand correctly the best method to handle this would be to pass the ID and run the query inside the show method instead of type hinting in the show method?

6th September, 2017

curtiplas started a new conversation Handling No Results On [email protected] Method • 3 months ago

So I thought I'd make this a different title name since there are so many as it relates to the "error" message: No query results for model [App\WaitList].

What I'd really like to know, is not WHAT that message means, but how to handle it better.

Essentially I want to be able to pass an id to the show controller then either return a view displaying the related model's info, OR return a view stating that the model doesn't exist (in this case a user/waitlister) then offer the option to join the waitlist.

Here is my current routes/web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

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

Auth::routes();

Route::get('/waitlist/join', '[email protected]');
Route::resource('waitlist', 'WaitListController', [
    'only' => 
        ['show', 'store', 'destroy']
    ]);

Here is my current WaitListController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\WaitList;
use App\Http\Requests\WaitlistRequest;
use App\Mail\WaitListWelcome;

class WaitListController extends Controller
{
    public function create()
    {
        return view('waitlist.create');
    }

    public function store(WaitListRequest $request)
    {
        //store in DB
        $waitlist = WaitList::create(
            request(['name', 'email'])
        );

        Mail::to($waitlist)->send(new WaitListWelcome($waitlist));

        session()->flash('message', 'Thanks for joining the wait list!');

        return redirect('/');
        //redirect
        
    }
    public function show(WaitList $waitlist){

        return view('waitlist.show', compact('waitlist'));
    }
}

As one would expect this works fine when a row exists in the waitlist table that matches the id I pass, but when it doesn't I get the standard laravel message telling me:

(2/2) NotFoundHttpException No query results for model [App\WaitList].

from playing with die & dumps it looks like this is thrown before anything inside the control method executes.

Any ideas on how I can handle this?

curtiplas left a reply on Handling The "No Query Results For Model" Error • 3 months ago

Hi @agahi not sure if you found the issue or not. But essentially that error is saying that it can't find anything in the table for the App\Element model with the id matching the $element item you sent.

Essentially the error is trying to tell you that nothing in the table you're pointing it at matches.

That said I'm trying to do the same thing you are I believe which is...

pass along the id or other Route Key Name to the show function on a controller. However, i want to be able to redirect the user to a different partial/page if nothing is matches the query it runs.

Would love to know if you got around it.

curtiplas left a reply on Generate Unique Database ID • 3 months ago

Very curious what method you ended up using @jaheller ...

1st September, 2017

curtiplas left a reply on Passing Data To A Mail Class • 3 months ago

So even though this is a 5.3 tutorial, this had the best description of laying out how to pass data between classes... turns out I was already doing it, just wasn't using it in my constructor.

https://mattstauffer.co/blog/introducing-mailables-in-laravel-5-3/

This is what my Mailable now looks like.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\WaitList;
use App\Http\Requests\WaitlistRequest;
use App\Mail\WaitListWelcome;

class WaitListController extends Controller
{
    public function create()
    {
        return view('waitlist.create');
    }

    public function store(WaitListRequest $request)
    {
        //store in DB
        $waitlister = WaitList::create(
            request(['name', 'email'])
        );

        Mail::to($waitlister)->send(new WaitListWelcome($waitlister));

        session()->flash('message', 'Thanks for joining the wait list!');

        return redirect('/');
        //redirect
        
    }

}

curtiplas started a new conversation Passing Data To A Mail Class • 3 months ago

I'm fairly new to laravel, but I'm working on creating a waitlist entry for a site. That said I've created a controller with a create method that shows the form, then a store method that is called when the form is posted back via a route to the controller. From here I call a form request to validate the form, then store the entry in the database. I'm then calling my mail class using the send function of the mail facade.

In the mail class I can get the request information, but this only contains the name and email, I'd like to pass the unique DB id of the user as I intend to create a unique link in the welcome email so they can update their preferences.

Here is my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\WaitList;
use App\Http\Requests\WaitlistRequest;
use App\Mail\WaitListWelcome;

class WaitListController extends Controller
{
    public function create()
    {
        return view('waitlist.create');
    }

    public function store(WaitListRequest $request)
    {
        //store in DB
        $waiter = WaitList::create(
            request(['name', 'email'])
        );

        Mail::to($waiter)->send(new WaitListWelcome($waiter)->with);

        session()->flash('message', 'Thanks for joining the wait list!');

        return redirect('/');
        //redirect
        
    }

}

Here is the form request

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class WaitListRequest extends FormRequest
{
    
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'email' => 'required|email|unique:wait_lists,email'
        ];
    }
}

And lastly here is the current mail class

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Http\Request;
use App\WaitList;

class WaitListWelcome extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build(Request $request)
    {
        dd($request);
        
        $name = $request->name;
        
        return $this->markdown('emails.waitlistwelcome')->with(Compact('name'));
    }
}

25th August, 2017

curtiplas left a reply on Unique Sql Rule - Sql Error "Integrity Constraint Violation: 1062 Duplicate Entry" • 3 months ago

Thanks @DanielBanciulea VERY helpful! I figured Laravel had to have an easy way to validate a unique field given that illuminate has a unique helper.

curtiplas left a reply on Form Request Validation, Class App\Http\Controllers\StoreBlogPost Does Not Exist • 3 months ago

Update: Fixed my issue,

Turned out to be a syntax error (missing a ',' in my array on the form request).

curtiplas left a reply on Form Request Validation, Class App\Http\Controllers\StoreBlogPost Does Not Exist • 3 months ago

I'm still having problems with my formRequest class.

This is my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\WaitList;
use App\Http\Requests\WaitlistRequest;

class WaitListController extends Controller
{
    public function create()
    {
        return view('waitlist.join');
    }

    public function store(WaitListRequest $request)
    {
        
        //store in DB
        $waiter = WaitList::create(
            request(['name', 'email'])
        );

        session()->flash('message', 'Thans for joining the wait list!');

        return redirect('/');
        //redirect
        
    }
}

Additionally this is my WaitListRequest:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class WaitListRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required'
            'email' => 'required|email'
        ];
    }
}

Lastly I did try did what @partyka.io mentioned above.

I'm still getting the following error when I post to the form:

(2/2) ReflectionException
Class App\Http\Requests\WaitlistRequest does not exist

9th August, 2017

curtiplas left a reply on Npm Install Hang • 4 months ago

Well installing grunt didn't help at all. However, I installed yarn and instead of bombing out at fsevents it reads it as an optional dependency.

I get the following:

[email protected]:~/projects/MusekClub$ sudo yarn install
yarn install v0.27.5
    Resolving packages...
    Fetching packages...
warning [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check.
Excluding it from installation.
    Linking dependencies...
    Building fresh packages...
Done in 67.15s.

What's better is it looks like it actually works as I'm now able to run yarn dev.

Thank you so much!!!

curtiplas left a reply on Npm Install Hang • 4 months ago

Okay broke out each of the devDependencies and installed them one by one... looks like the error is getting called by the dependency.

"laravel-mix": "^1.0"

Any thoughts on how to get around this??

curtiplas left a reply on Npm Install Hang • 4 months ago

Just an update. I completely rebuilt the vagrant box from scratch and tried again. same issue.

Here is the cmd ln output:

[email protected]:~/projects/MusekClub$ sudo npm install
npm ERR! path /home/vagrant/projects/MusekClub/node_modules/fsevents/build/Release/.deps/User/eshanker/Code/fsevents/lib
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rmdir
npm ERR! ETXTBSY: text file is busy, rmdir '/home/vagrant/projects/MusekClub/node_modules/fsevents/build/Release/.deps/Users/eshanker/Code/fsevents/lib'

npm ERR! A complete log of this run can be found in:
npm ERR!    /home/vagrant/.npm/_logs/2017-08-09T12_45_58_590Z-debug.log
-```

7th August, 2017

curtiplas left a reply on Npm Install Hang • 4 months ago

Just to update everyone on the status, I completely removed npm and reinstalled it following:

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

for node.js 8

I then ran 'sudo npm install --verbose' directly from the host vm via virtualbox bypassing the vagrant ssh; but it still bombs out on me; thistime with a slightly different error. but still surrounding fsevents.

npm verb stack Error: EPERM: operation not permitted, scandir '/home/vagrant/projects/MusekClub/node_modules/fsevents/node_modules'
npm verb cwd /home/vagrant/projects/MusekClub
npm verb Linux 3.13.0-125-generic
npm verb argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "--no-bin-links" "--verbose"
npm verb node v8.2.1
npm verb npm  v5.3.0
npm ERR! path /home/vagrant/projects/MusekClub/node_modules/fsevents/node_modules
npm ERR! code EPERM
npm ERR! errno -1
npm ERR! syscall scandir
npm ERR! Error: EPERM: operation not permitted, scandir '/home/vagrant/projects/MusekClub/node_modules/fsevents/node_modules'
npm ERR!  { Error: EPERM: operation not permitted, scandir '/home/vagrant/projects/MusekClub/node_modules/fsevents/node_modules'
npm ERR!   stack: 'Error: EPERM: operation not permitted, scandir \'/home/vagrant/projects/MusekClub/node_modules/fsevents/node_modules\'',
npm ERR!   errno: -1,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'scandir',
npm ERR!   path: '/home/vagrant/projects/MusekClub/node_modules/fsevents/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm verb exit [ -1, true ]

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vagrant/.npm/_logs/2017-08-07T21_30_18_892Z-debug.log

curtiplas started a new conversation Npm Install Hang • 4 months ago

Hello All, I'm unable to get npm installed correctly in my laravel project. I'm running laravel on a vagrant box (ubuntu-trusty-64). When I run 'npm install' I get the first error in my pastebin (linked below). I then found somewhere below that I should run it without symlinks when using a vagrant box on a windows host os so I then ran 'npm install --no-bin-links' and I was still getting the first error. So then with some help I ran 'rm -rf node_modules' then ran the 'npm install --no-bin-links' and it appears to work but hangs see second half of the pastebin.

Please help!

pastebin: https://pastebin.com/wuRkjqi6

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.