WallyJ

WallyJ

Member Since 2 Years Ago

Experience Points 4,640
Experience Level 1

360 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 12
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.

15 May
4 days ago

WallyJ left a reply on Best Autocomplete For Laravel Projects With MySQL Backend

@robstar Yes, though, I am trying to remove the step of them having to click a Search button after choosing a name.

For instance, there are online editors for websites that allow you to choose a font for some text.

You can either click the font dropdown arrow, or start typing in the input box. It autocompletes as you type, and once you see the name of the font you want to use, you click on it. Once you click, it immediately fills the box with the name of the font you chose, but it also changes the font of the text.

You don't have to search, then click on the font name, then ALSO click on a "Change Font" button.

Search, click, action occurs. No other buttons or manual form submissions.

That is my goal.

Type a name, click it, immediately sends that name to a route for me to open the index view for that record (or whatever else I might want to do with that value)

Make sense?

14 May
5 days ago

WallyJ left a reply on Best Autocomplete For Laravel Projects With MySQL Backend

@snapey One other thought, for some applications, like looking up a Client Account by name, wouldn't it be easier for the end user to type in the name and when they see the correct name, to simply click on the name and it take them to the Client View, rather than clicking the name, then clicking "Submit" or "Search"?

This is the functionality I'm going for. Thanks!

WallyJ left a reply on Best Autocomplete For Laravel Projects With MySQL Backend

@robstar Youmay very well be right. I have just never used Vue before, so it isn't as obvious to me.

I started using Laravel before Vue was used with it with regularity. But I appreciate the suggestion!

WallyJ left a reply on Best Autocomplete For Laravel Projects With MySQL Backend

@punksolid Thanks! I'll check that out and let you know what I go with.

@snapey Very good point. You are helping me rethink my functionality. I'm trying to make it easier on the user to look up a particular record.

Thank you both!

13 May
6 days ago

WallyJ started a new conversation Best Autocomplete For Laravel Projects With MySQL Backend

I normally receive awesome help from these forums, but in the Javascript category I posted a question here about Typeahead.js and have received no replies:

https://laracasts.com/discuss/channels/javascript/add-links-to-typeahead-results

That may be my fault in the way I asked the question,

But I'm just trying to get an autocomplete search field set up and can't get Typeahead to add links to the results.

I'm starting to think there is a better autocomplete to use within a Laravel project, or at least on that is more current/has better support.

You guys are the best so I thought I would throw this out there.

I appreciate any help provided. Thanks so much!

09 May
1 week ago

WallyJ left a reply on JQuery Not Working In Blade Template

@SNAPEY - I wasn't sure what that file was for. It was there by default so I just ignored it. I don't currently us Vue at all, so I commented it out and... Voila!! It works now!

Thanks!

Now I just have to figure out how to add links into the results so they're clickable. I put another post into the Javascript forum about that. :)

WallyJ started a new conversation Add Links To Typeahead Results

Typeahead noob here.

This is my Typeahead script:

<script type="text/javascript">
    var path = "{{ route('autocomplete') }}";
    $('input.typeahead').typeahead({
        source:  function (query, process) {
        return $.get(path, { query: query }, function (data) {
            // return '<a href="' + data.profile.username + '" class="list-group-item">' + data.name + ' - @' + data.profile.username + '</a>'
            // return "<a href=" + data.id + ">"+ data.name +"</a>"
            return process(data);
            });
        }
    });
</script>

I want the results (names from a database query, to be links to the individual user pages, whose links would include the id of the user.

I tried:

return "<a href=" + data.id + ">"+ data.name +"</a>"

But this broke the functionality entirely.

Please advise. Thanks!

WallyJ left a reply on JQuery Not Working In Blade Template

This is the "head" section of my app.blade.php (No scripts at the bottom of the page)

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'DocuClub') }}</title>

    <!-- Scripts -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>
    
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">

This is the actual script on the index.blade.php page for Typeahead JS:

<script type="text/javascript">
    var path = "{{ route('autocomplete') }}";
    $('input.typeahead').typeahead({
        source:  function (query, process) {
        return $.get(path, { query: query }, function (data) {
                return process(data);
            });
        }
    });
</script>

WallyJ left a reply on JQuery Not Working In Blade Template

I thought that it was using the typehead version of that file through this link:

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>

I did see one error:

Uncaught TypeError: Cannot read property 'fn' of undefined
    at bootstrap3-typeahead.min.js:1
    at bootstrap3-typeahead.min.js:1
    at bootstrap3-typeahead.min.js:1
(anonymous) @ bootstrap3-typeahead.min.js:1
(anonymous) @ bootstrap3-typeahead.min.js:1
(anonymous) @ bootstrap3-typeahead.min.js:1
08 May
1 week ago

WallyJ started a new conversation JQuery Not Working In Blade Template

I am trying to use Typeahead to create an autocomplete search box in a view.

If I copy the full code from the tutorial into a blade file WITHOUT any @extends or @section areas, it works fine.

If I try to add the links and scripts to app.blade.php,

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>

It seems to load in the browser fine, per the Chrome Inspection tool, but the functionality doesn't work.

The links in the head are there. The scripts at the bottom are there. I don't know why it isn't firing properly. When the code is on one page it works fine. When it comes from separate sections through Blade, it doesn't work. Anyone else seen this issue?

WallyJ left a reply on ReflectionException Class App\Http\Controllers\User Does Not Exist

@XSECRETS - @xsecrets - Worked like a charm. After adding that, I was able to delete the unnecessary controller "User.php" and everything works without errors. Thanks!

WallyJ left a reply on ReflectionException Class App\Http\Controllers\User Does Not Exist

UPDATE

To see if I could simply bypass the error, I recreated the "User" controller the way I did at the beginning and the error went away. "UserController" is still working properly, so there is something referencing the "User" controller that needs it to exist even though it isn't doing anything. Might be a bug. I'll keep on truckin'.

Open to any thoughts. Thanks.

WallyJ left a reply on ReflectionException Class App\Http\Controllers\User Does Not Exist

Good idea. Just tried it. Same error message.

As a side note, if I try to perform:

php artisan optimize

I get this error:

LogicException  : Unable to prepare route [api/user] for serialization. Uses Closure.

at C:\laragon\www\Docuclub\vendor\laravel\framework\src\Illuminate\Routing\Route.php:917
    913|      */
    914|     public function prepareForSerialization()
    915|     {
    916|         if ($this->action['uses'] instanceof Closure) {
  > 917|             throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure.");
    918|         }
    919|
    920|         $this->compileRoute();
    921|

  Exception trace:

  1   Illuminate\Routing\Route::prepareForSerialization()
      C:\laragon\www\Docuclub\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:62

  2   Illuminate\Foundation\Console\RouteCacheCommand::handle()
      C:\laragon\www\Docuclub\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32

WallyJ left a reply on ReflectionException Class App\Http\Controllers\User Does Not Exist

@edoc , Yes I did. I have updated my post to show my UserController and my Route for the link that is giving me the error.

WallyJ started a new conversation ReflectionException Class App\Http\Controllers\User Does Not Exist

I added the "User" controller through

php artisan make:controller User

and hit enter before I realized I didn't add the word "Controller" to the end.

I changed it in the file name, and in web.php, but I still receive the error:

ReflectionException Class App\Http\Controllers\User does not exist

I'm not sure where else to look. I don't see where I have referenced the Controller with just "User".

Thanks.

07 May
1 week ago

WallyJ left a reply on Cloud9 Auth Links Not Working

Now I'm running into the following error: Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Class 'PDO' not found

I manually installed PDO via the command line, but can't perform a "service httpd restart".

It won't stop the service to start it again. Then I realized the first issue is why I left Paiza Cloud in the first place, thinking it was their fault.

Loaded up Paiza again and now I click on the "Register" link and I receive this error:

Please use HTTPS(SSL) instead of HTTP to access the URL.

I figure this is a Paiza issue, but I can't find anything online about that particular error.

Why can't anyone make an online IDE that runs smooth like Laragon does locally. Any advise would be appreciated.

WallyJ left a reply on Cloud9 Auth Links Not Working

So, interestingly, as I kept trying over and over, something caught my eye, up in the actual Chrome browser window I saw a shield icon pop up when i clicked "Register". Chrome was seeing my app as an unauthenticated script or something. So I told it to allow, and now it seems to be working. So far... Anyone else run into this?

WallyJ started a new conversation Cloud9 Auth Links Not Working

I installed Laravel onto a Cloud9 server, and installed auth using "php artisan make:auth".

I refreshed the page to see the "Login" and "Register" links prominently displayed in the upper right of the browser window as expected.

But if I click the links, they do nothing... absolutely nothing. I double-checked to make sure that "Auth::routes()" was added to web.php and it was. I'd rather have an error message. That I could do something with.

Anyone know why this behavior would be happening?

Thanks.

12 Feb
3 months ago

WallyJ started a new conversation ForEach Loop Results Assigned To Variable In Blade

This may have to be done in the controller, but in blade I have a working foreach loop:

@foreach($opps as $opp)
{{$opp->oppNumber}}, 
@endforeach

Which returns a string that has each number followed by a comma and a space.

I need to assign this string of numbers, commas, and spaces to a variable ($opplist) so that I can assign the string as a value of an input field. I am assigning this value to a hidden input field so that I can assign it to a "data-clipboard-target" button so that the entire list can be copied by clicking a button.

I'm just not sure how to assign the string to the value of the hidden input field.

The normal hidden input field code looks like this:

<input type="hidden" id="#copy_opplist" value="$opplist}}">
<button class="btn btn-success btn-sm" data-clipboard-target="#copy_opplist">Copy List</button>

If there's a better way to do this, I'm open to suggestions.

I'm thinking that maybe I should do the foreach in the controller and define the variable there then pass the variable to the view to use in the input field, but I'm not sure how to assign the foreach to a variable in a controller either.

Thanks.

WallyJ left a reply on Error When Using Auth::attempt To Check For Active User

Yes. I set the default value to 0 and change the value to "1" when a user has paid.

WallyJ left a reply on Error When Using Auth::attempt To Check For Active User

I'm realizing now that this code can really only be used as a person is logging in, if I'm using manual authentication, which I'm not.

So, it seems that I need to use the "isActive" approach, but I don't understand what the line "return $this->active" does. How does that code check to see if the Active value of the logged in user is set to "1"?

WallyJ left a reply on Error When Using Auth::attempt To Check For Active User

That makes sense about the variable.

And I want to use the Auth method correctly. Not simply fix my issue by writing my own custom classes.

I don't understand why it is throwing the error that I am receiving other than the variable missing in the controller.

So it seems that the code I see in the docs is intended for Controllers, not views, but this makes me ask, so, how do most people use the Auth method in the scenario I described?

By the docs, they use redirect, so I think they plan on having a home page that is primarily designed for non-logged in or non-active users, and then they use redirect for those who are "Active", in the case I am using. I am going to try to use that concept and see how it goes.

Thanks.

WallyJ left a reply on Error When Using Auth::attempt To Check For Active User

But what about for a user who is already logged in. and then they are made active, and they refresh the page.

Why should this return the error that I mentioned, if they were seeing everything just fine using Auth::check?

WallyJ started a new conversation Error When Using Auth::attempt To Check For Active User

I have been using Auth::check() in my app for checking for logged in users, but now I want to change that to only check for active users, planning on marking users active once they have purchased a subscription to be a paid user (active) rather than a free user.

Looking at the docs, I used this syntax:

if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
    // The user is active, not suspended, and exists.
}

I tried to use this syntax in a view, but it gives me the error "Undefined variable: email".

Not sure what is wrong. Thanks.

20 Dec
4 months ago

WallyJ left a reply on Accessor Full_name Breaks AJAX Lookup

@Cronix Your code is giving me a 500 internal server error on the "fetch" function in my controller, in the console as I type in the search box. I fixed the missing semicolon at the end of the line in the model, but are you sure that "fullname_like($query)" is the right syntax? The model code seems to be correct since the error is thrown on "/fetch" which is in the controller.

WallyJ left a reply on Accessor Full_name Breaks AJAX Lookup

@Cronix Makes perfect sense. Thanks!

08 Dec
5 months ago

WallyJ left a reply on Accessor Full_name Breaks AJAX Lookup

Thanks @cronix ! For the sake of my understanding, is there a specific reason you wouldn't use one of the other methods I mentioned?

07 Dec
5 months ago

WallyJ left a reply on Accessor Full_name Breaks AJAX Lookup

@realrandyallen , Thanks for the suggestion, though I received an error with your code concerning the }. Probably a syntax issue.

@cronix , I used your code and it worked perfectly. I had to add the additional last name to the "li" element so that the last name would show up in the list, but now it does.

The only issue I have now is that the search box only works on the Dashboard page (the controller code I gave).

Should I add the function from the Controller to a helper file if I want it available for all views (since it is in the nav bar of the app.blade.php file it will essentially be available almost everywhere)?

Or should I add it to something like common.php and use:

use Common

in every controller?

Now that it works, I don't want to break it again by making it globally available.

Thanks again!

WallyJ started a new conversation Accessor Full_name Breaks AJAX Lookup

The following code was working until I replaced "contact1firstname" (a single field in the db), with "full_name", an Eloquent Accessor that combines "contact1firstname" and "contact1lastname" for the sake of searching the combined fields rather than just the first name. Now when I type in my search box nothing happens.

Contact Model:

public function getFullnameAttribute()
    {
        return "{$this->contact1firstname} {$this->contact1lastname}";
    }

Controller:

public function fetch(Request $request)
    {
        $user_id = auth()->user()->id;
        if($request->get('query'))
        {
            $query = $request->get('query');
            $data = Contact::where('user_id', '=', $user_id)
            ->where('full_name', 'LIKE', '%'.$query.'%')
            ->get();
            $output = '<ul class="dropdown-menu" style="display:block; position:relative">';
            foreach($data as $row)
            {
                $output = '<li class="dropdown-item"><a href="#">' .$row->full_name. '</a></li>';
                echo $output;
            }
            $output = '</ul>';
        }
    }

View (Search Box and Script):

<ul class="nav navbar-nav mx-auto form-group" style="display:block; position:relative">
<li class="nav-item dropdown">
<input type="text" class="form-control" name="contactsearchBox" id="contactsearchBox" placeholder="Search">
</li>
<div class="dropdown-menu" aria-labelledby="navbarDropdown" id="contactList"></div>
{{ csrf_field() }}
</ul>

<script src="{{ asset('js/app.js') }}"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    
    <script type="text/javascript">
        $(document).ready(function() {
            $('#contactsearchBox').keyup(function() {
                var query = $(this).val();
                console.log(query);                
                if (query !='')
                    {
                        $.ajaxSetup({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            }
                        });
                        $.ajax({
                            url:"{{ route('dashboard.fetch') }}",
                            method:"POST",
                            data:{
                                query : query 
                                // '_token': 'X-CSRF-TOKEN',
                                // _token : _token
                            },
                                success:function(data)
                                {
                                    $('#contactList').fadeIn();
                                    $('#contactList').html(data);
                                }
                            })
                        }
                    });
                $(document).on('click', 'a', function(){
                    $('#full_name').val($(this).text());
                    $('#contactList').fadeOut();
                });
            });
    </script>

I'm sure it's something I'm doing wrong with the Accessor, but I'm not sure what. Thanks!

16 Nov
6 months ago

WallyJ left a reply on 500 Internal Server Error - Submitting Form To Route Through Ajax

@TALINON - console.log(data) is not in the success method. console.log(query) is just after the query variable is declared so I can test it in the console to make sure the characters are being picked up as I type them, if that's what you mean.

WallyJ left a reply on 500 Internal Server Error - Submitting Form To Route Through Ajax

@CRONIX - Good word! I am also using the search box as part of a Bootstrap Navbar, so I'm having to rethink the formatting portion of my code, but that is a great fix to the loop portion. I want the search box to be in the center of the navbar at the top and the autocomplete search results to be directly below the search box. I want it in the navbar so it can be used on any page a user might be on.

WallyJ left a reply on 500 Internal Server Error - Submitting Form To Route Through Ajax

I changed my where line with the wildcard to :

->where('contact1firstname', 'LIKE', '%'.$query.'%')

And I am now getting results. Thanks all!

WallyJ left a reply on 500 Internal Server Error - Submitting Form To Route Through Ajax

@TALINON - Interestingly, after I removed the first get(), the 500 error went away, and the

console.log(query); 

line is sending the string to the console each time I type a character (used for testing), but the Autocomplete box seems to do nothing. So now I removed the error, but am only filling the "query" variable. The list of contacts is not showing.

WallyJ left a reply on 500 Internal Server Error - Submitting Form To Route Through Ajax

@JLRDW - With jQuery Autocomplete you don't need a complete form, just the form field itself, see https://jqueryui.com/autocomplete/

WallyJ started a new conversation 500 Internal Server Error - Submitting Form To Route Through Ajax

I have a JQuery Autocomplete that is throwing a 500 Internal Server Error as I type in the text field, and thought this may seem more like a JQuery or Ajax issue, I believe the problem lies in how Laravel is handling the CSRF token as part of the process. Here is my code (relevant parts):

Form in Blade:

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Styles -->
    
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    {{-- <link href="{{ asset('css/app.css') }}" rel="stylesheet"> --}}
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />

</head>
<body>

<div class="nav navbar-nav mx-auto form-group">
<input type="text" class="form-control" name="contactsearchBox" id="contactsearchBox" placeholder="Search">
<div id="contactList"></div>
{{ csrf_field() }}
</div>

<!-- Scripts -->
    <script src="{{ asset('js/app.js') }}"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    
    <script type="text/javascript">
        $(document).ready(function() {
            $('#contactsearchBox').keyup(function() {
                var query = $(this).val();
                console.log(query);                
                if (query !='')
                    {
                        $.ajaxSetup({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            }
                        });
                        $.ajax({
                            url:"{{ route('dashboard.fetch') }}",
                            method:"POST",
                            data:{
                                query : query 
                                // '_token': 'X-CSRF-TOKEN',
                                // _token : _token
                            },
                                success:function(data)
                                {
                                    $('#contactList').fadeIn();
                                    $('#contactList').html(data);
                                }
                            })
                        }
                    });
                $(document).on('click', 'li', function(){
                    $('#contact1firstname').val($(this).text());
                    $('#contactList').fadeOut();
                });
            });
    </script>

    
</body>
</html>

Controller:

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Profile;
use App\User;
use Auth;
use App\Contact;

public function fetch(Request $request)
    {
        $user_id = auth()->user()->id;
        if($request->get('query'))
        {
            $query = $request->get('query');
            $data = Contact::where('user_id', '=', $user_id)->get()
            ->where('contact1firstname', 'LIKE', '%{$query}%')
            ->get();
            $output = '<ul class="dropdown-menu" style="display:block; position:relative>';
            foreach($data as $row)
            {
                $output .= '<li><a href="#">' .$row->contact1firstname. '</a></li>';
                $output .= '</ul>';
                echo $output;
            }
        }
    }

I tried to follow the instructions found here - https://laravel.com/docs/master/csrf concerning the use of the CSRF token.

Thanks.

12 Nov
6 months ago

WallyJ left a reply on Paginating Eloquent Relational Query Results - Eager Loading

After rethinking my efforts, I believe I am going to switch to using JQuery to create an infinite scroll within the div that contains my data, rather than using pagination. No clicking needed, just the scroll wheel.

06 Nov
6 months ago

WallyJ started a new conversation Paginating Eloquent Relational Query Results - Eager Loading

I'm trying to have a section on my contact view that shows contact notes, 4 per page, in a box that goes through pages without refreshing the page. This may require AJAX, but I'm just trying to get the pagination to show at the moment.

Here's my code. Since I'm using the "with" to eager load the "contactnotes", I don't know where to put the pagination function.

Contacts Controller:

//Look up contact chosen by URL
        $contacts = Contact::with(['contactnotes', 'deals.tasks'])->find($id);

        // Check for correct user
        
        if(auth()->user()->id !== $contacts->user_id){
            return redirect('/contacts')->with('error', 'That Is Not Your Contact');
        }

        // Update Last Seen Field for viewed contact
        Contact::where('id', $id)
                    ->update(['contactlastseen' => \Carbon\Carbon::now()]);

        return view('contacts.show', ['contact' => $contacts, 'contactnotes' => $contacts->contactnotes, 'deals' => $contacts->deals]);

View:

<div class="col-md-12">
  <ul class="list-group">
    @foreach($contactnotes->sortByDesc('created_at') as $contactnote)
    <li class="list-group-item">
    {{$contactnote->created_at->diffForHumans()}} - {{$contactnote->contactnotetext}}
    </li>
    @endforeach
  </ul>
</div>

I may ultimately go with a static box with a scroll bar and add infinite scroll capabilities to it, so it doesn't take up much space on the screen and would also not require a page refresh.

Ideas? Thanks!

10 Oct
7 months ago

WallyJ left a reply on ID Does Not Pass From View To Controller

@Cronix , You are correct. I am using a resource controller.

I didn't realize that those controllers could not receive parameters like that.

I guess this is one problem with combining so many learning resources that tutorials get combined into things that sometimes don't work together. I never thought about passing the variable through a hidden field in the form.

Now when I dd($contact), I get the entire record for the correct contact in the DB.

Edited the rest of my code and my form works like a champ now. Thanks!

And thanks to everyone for their feedback. This community is awesome!

WallyJ left a reply on ID Does Not Pass From View To Controller

@jekinney , thanks for the ideas. The form helpers are part of LaravelCollective who continued developing them when Laravel took them out of the framework.

www.laravelcollective.com

I checked the dd and it shows nothing, however, I'm wondering how my route can be wrong when the form sends the information directly to the controller via this line:

{!! Form::open(['route' => ['contactnotes.store', $contact->id]]) !!}

WallyJ left a reply on ID Does Not Pass From View To Controller

@D9705996 , The url the form is on includes something like /contact/5, so the ID is being sent to that page. The contact_id is in the controller, and pulls the $contact->id

@jlrdw , The other fields are passed since "contactnotetext" shows up in the results.

WallyJ started a new conversation ID Does Not Pass From View To Controller

Relationships are set in the model

Form in view:

{!! Form::open(['route' => ['contactnotes.store', $contact->id]]) !!}
                                    {{ csrf_field() }}
                                    <div class="form-group">
                                        {{Form::textarea('contactnotetext', null, array('placeholder' => 'Your note here', 'class' => 'form-control', 'rows' => '3'))}}
                                    </div>
                                    <div class="form-group">
                                        {{Form::submit('Add Note', array('class' => 'btn btn-primary'))}}
                                    </div>
{{Form::close()}}

ContactnotesController:

public function store(Contact $contact, Request $request)
    {
        $contactnote = new Contactnote;
        $contactnote->contact_id = $contact->id;
        $contactnote->contactnotetext = $request->contactnotetext;
        $contactnote->contact()->associate($contact);
        return $contactnote;
    }

I don't understand why the id is not being passed. When I submit the form I get:

{
"contact_id": null,
"contactnotetext": "adsf",
"contact": []
}
08 Oct
7 months ago

WallyJ left a reply on Trying To Get Property Of A Non-object - First()

It was in a foreach loop. I added the optional helper and it worked fine. Thanks!

WallyJ started a new conversation Trying To Get Property Of A Non-object - First()

When I use:

{{$deal->tasks->first()}}

in a view, I get this when rendered:

{"id":1,"created_at":"2018-10-01 00:00:00","updated_at":"2018-10-01 00:00:00","deal_id":11,"tasktext":"Call Client","taskduedate":"2018-04-20","taskcomplete":0}

When I add the following:

{{$deal->tasks->first()->tasktext}}

I get "Trying to get property of a non-object". I can see the field of the record from the previous code. How am I not calling it correctly?

WallyJ left a reply on Limit Results In Eloquent Results Using Relationship Table

@snapey - Looks like that works. I'm going to run some more tests to make sure. I did have something in my view like that. Just didn't click with me. Thanks!

WallyJ left a reply on Limit Results In Eloquent Results Using Relationship Table

@Snapey , does that go in the controller? And if so, where? Thanks!

04 Oct
7 months ago

WallyJ left a reply on Limit Results In Eloquent Results Using Relationship Table

@Cronix , that code returns a total of 3 records across all contacts, not 3 for each contact.

@Snapey , Thanks for the link. I've seen it during my debugging research. There isn't really a clear workaround in that post. Also, it is disheartening to see a bug report like that from 2014 that still doesn't have a clear fix from Laravel or @TaylorOtwell . For a new programmer like me Laravel is supposed to make "plain language" programming easier, and this is a very simple concept. But this is discouraging.

02 Oct
7 months ago

WallyJ left a reply on Limit Results In Eloquent Results Using Relationship Table

The code I placed returns the correct records as written. It returns ALL contacts for the logged in user. It also shows EVERY contact note under every contact. I want it to show ALL contacts, but I don't want it to show ALL the contact notes.

I want the query to limit the number of contact notes for each contact to the latest 3 (not all). So if a logged in user has 10 contacts, each of those contacts has over 100 notes each, that dashboard gets long and unreadable really fast. But if each contact record in the collection only returned the most recent 3 notes, that would be manageable.

Hopefully that makes better sense.

WallyJ started a new conversation Limit Results In Eloquent Results Using Relationship Table

The following code returns "Contacts" with their "Contactnotes", that belong to a given logged in user, in descending order correctly. I am trying to limit the notes per Contact to 3. I tried to add "take(3)" to the $query statement, but it limited the entire result to only 3 contact notes across all contacts. I believe I need to add a @foreach statement to my query, but I'm not sure how.

public function index()
    {
        //Look up contacts associated with the logged in user
        $user_id = auth()->user()->id; 
        $user = User::find($user_id);;
        $contacts = Contact::with(['contactnotes' => function($query) {
            $query->orderBy('updated_at', 'desc');
        }])
        ->with('deals')
        ->orderBy('contact1lastname', 'asc')
        ->where('user_id', '=', $user_id)->get();
        return $contacts;
        return view('dashboard')
        ->with('contacts', $contacts);
    }
27 Sep
7 months ago

WallyJ left a reply on Access Relations Field In View - Property [contactnotetext] Does Not Exist On This Collection Instance

@Snapey , I received the error "Method Illuminate\Database\Eloquent\Collection::with does not exist." on the simplified code you gave me.

WallyJ left a reply on Access Relations Field In View - Property [contactnotetext] Does Not Exist On This Collection Instance

I'm looking to order the contactnotes (not contacts) by the date field (updated_at), and in some views to limit the list to the latest 3 comments.