jlrdw

jlrdw

Member Since 3 Years Ago

Experience Points 328,760
Experience Level 50

0 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 100
Lessons
Completed
Best Reply Awards 338
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.

21 May
19 hours ago

jlrdw left a reply on Posting Ajax Data To Laravel 5.7 Gives JS Error 500

Have you tried the get method for returning back to Ajax.

jlrdw left a reply on Error When Deployed But Works Local

Just a quick thought on it have you checked your letter case Linux is case sensitive.

jlrdw left a reply on How To Show Default Value In Select Option (parent_id)?

did you even bother to look at the link I gave. You get answers to your questions but you are always ignoring.

jlrdw left a reply on Want To Disable This Method In Form Request Validation File

@TOWHID - Remember, clear cache after changes.

jlrdw left a reply on How To Show Default Value In Select Option (parent_id)?

I think OP means what is currently stored in the DB. (I think)

See https://laracasts.com/discuss/channels/laravel/how-do-i-assign-the-existing-value-to-a-select

By retrieving what's stored just like inputs.

jlrdw left a reply on Simple Use Of Eloquent Join

learning Laravel ways

No arguments here but very vague.

For simple relation ORM is fine, but for more complex I perfer this style:

$quy = Powner::query()->leftJoin('dc_pets', 'dc_powners.ownerid', '=', 'dc_pets.ownerid')
                ->select('dc_powners.ownerid', 'dc_powners.oname')
                ->selectRaw('count(dc_pets.petid) as countOfPets')
                ->groupby('dc_powners.ownerid')
                ->orderby('dc_powners.oname')
                ->get();

Results basically give:

ownerid, oname, countOfPets

Like:

5|Bob|3
4|Greg|9
2|Rob|1

After QB, Eloquent, (active record) it goes through the various methods which determine what type relation and exactly what query type is needed it's all done via normal PDO:

Quote:

    public function select($query, $bindings = [], $useReadPdo = true)
    {
        return $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
            if ($this->pretending()) {
                return [];
            }
            // For select statements, we'll simply execute the query and return an array
            // of the database result set. Each element in the array will be a single
            // row from the database table, and will either be an array or objects.
            $statement = $this->prepared($this->getPdoForSelect($useReadPdo)
                              ->prepare($query));
            $this->bindValues($statement, $this->prepareBindings($bindings));
            $statement->execute();
            return $statement->fetchAll();
        });
    }

Unquote as example

Which is not the same but similar to a framework I contributed to:

    public function select($sql, $array = array(), $fetchMode = PDO::FETCH_OBJ, $class = '')
    {
        $stmt = $this->prepare($sql);
        foreach ($array as $key => $value) {
            if (is_int($value)) {
                $stmt->bindValue("$key", $value, PDO::PARAM_INT);
            } else {
                $stmt->bindValue("$key", $value);
            }
        }

        $stmt->execute();

        if ($fetchMode === PDO::FETCH_CLASS) {
            return $stmt->fetchAll($fetchMode, $class);
        } else {
            return $stmt->fetchAll($fetchMode);
        }
    }

Where $array is the bindings.

In fact Active record reduces down to this at runtime:


$sql = "SELECT dc_powners.ownerid, dc_powners.oname, ";
          $sql .= "COUNT(dc_pets.petid) AS CountOfpetid ";
          $sql .= "FROM dc_powners LEFT JOIN dc_pets ON ";
          $sql .= "dc_powners.ownerid = dc_pets.ownerid ";
          $sql .= "GROUP BY dc_powners.ownerid ";
          $sql .= "ORDER BY dc_powners.oname";

In other words regular sql

Many here write queries laravel agnostic, which is fine.

But I like queries that can easily be brought over to another framework is needed.

For example the above works here, yii2, or cakephp. All the major frameworks have the PDO instance.

And eloquent uses the exact same.

No arguments, but if you want active record fine, but don't judge one if they prefer normal queries if the query is a little more complex. I in fact prefer getPdo() for many things.

Taylor doesn't force any "way" of getting DB results.

But if using normal sql use proper bindings as needed.

jlrdw left a reply on Mergin Two Collections Only Returns One

Just query what you need and just display it, merging the collection combines them, that's expected Behavior.

Look at query scopes.

jlrdw left a reply on Implementing 3 Types Of Users

You saying you can't have a table with roles.

You determine if a role matches.

Did you even follow my suggestion above as multiple tables has also been covered.

jlrdw left a reply on Getting Values From Radio Button

If solved, are you going to mark it solved.

jlrdw left a reply on Destroying Only The Login Session

If you are logging in a user in a framework like laravel and you do not understand how a cookie works in conjunction with session you probably need to take some basic tutorials.

jlrdw left a reply on Implementing 3 Types Of Users

The authorization and Authentication with multiple tables versus one table has been covered in the Forum very well before.

Google:

Site:laracasts.com your search term

There is many prior coverage is on this.

jlrdw left a reply on Laravel 5.7 + Jasper

Can't understand why you would need something like Jasper reports with just a little bit of join and group by you can very easily write your own

Just examples

Also I just gave a quick answer a while back to someone looking for join and group by together.

This is just an example:

$quy = Powner::query()->leftJoin('dc_pets', 'dc_powners.ownerid', '=', 'dc_pets.ownerid')
                ->select('dc_powners.ownerid', 'dc_powners.oname')
                ->selectRaw('count(dc_pets.petid) as countOfPets')
                ->groupby('dc_powners.ownerid')
                ->orderby('dc_powners.oname')
                ->get();

Results basically give:

ownerid, oname, countOfPets

Like:

5|Bob|3
4|Greg|9
2|Rob|1
// more
20 May
1 day ago

jlrdw left a reply on Htmlspecialchars() Expects Parameter 1 To Be String, Array Given

@ETERNALCHAOS520 - It would not hurt you to take some real basic HTML JavaScript and PHP tutorials.

Perhaps some basic CSS also.

jlrdw left a reply on Understanding Token Usage Auth

I have not deeply searched this, but one class depends on another class it takes some jumping around in the API two piece everything together.

https://laravel.com/api/5.8/Illuminate/Auth/Passwords/TokenRepositoryInterface.html#method_create

jlrdw left a reply on Understanding Token Usage Auth

Search the API. It has links to where the code is also.

jlrdw left a reply on Distinct And OrderBy Not Working

did you clear your config.

jlrdw left a reply on Distinct And OrderBy Not Working

Have you read about pagination in the documentation.

jlrdw left a reply on What Is The Best Starting Point For A Non-developer?

Highly suggest some basics first:

https://www.w3schools.com/

  • html
  • css
  • basic javascript
  • php

jlrdw left a reply on Query Using Max And Group

A join and a group by example is something like

This is just an example:

$quy = Powner::query()->leftJoin('dc_pets', 'dc_powners.ownerid', '=', 'dc_pets.ownerid')
                ->select('dc_powners.ownerid', 'dc_powners.oname')
                ->selectRaw('count(dc_pets.petid) as countOfPets')
                ->groupby('dc_powners.ownerid')
                ->orderby('dc_powners.oname')
                ->get();

Results basically give:

ownerid, oname, countOfPets

Like:

5|Bob|3
4|Greg|9
2|Rob|1
// more

Example uses count just change to Max or whatever aggregate you need.

jlrdw left a reply on Laravel DB::query To Eloquent

See https://laracasts.com/discuss/channels/eloquent/why-doesnt-laravel-use-joins-when-pulling-belongsto-or-hasone

Different query types are used for different purposes usually a master detail it's more like an invoice is the master and the details on that invoice would be the children.

Joins and group by are usually more for monthly and quarterly reports things like that.

So the type of query depends on what data you are trying to get and why.

jlrdw left a reply on When I Change The Quantity Of My Items, The Total Doesn't Update (PHP)

Why don't you take some quality time relax a little and take some of Jefferies free video training.

It might just help you quite a bit.

jlrdw left a reply on Laravel App To Mobile App .How To Convert ????????

Do you need mobile app or just mobile-friendly. Which is usually handled using media queries. And of course images are optimized for the web.

19 May
2 days ago

jlrdw left a reply on Where Correct Word

@WILK_RANDALL - Sorry I missed the "not".

We are lucky if some read the laravel docs, haha.

jlrdw left a reply on Where Correct Word

@WILK_RANDALL - I'm sure you meant case in-sensitive.

Was hoping OP would actually consult the MySql manual.

jlrdw left a reply on Where Correct Word

I am just guessing you are using mysql. Have you studied he chapters in the docs on sql selects, etc.

https://dev.mysql.com/doc/refman/8.0/en/

Run the query in your mysql front. I use sqlyog, but whatever you use. Learn a little, experiment a little.

jlrdw left a reply on Multi User Authentication System Using Laravel's Default Authentication System

See here https://laracasts.com/discuss/channels/laravel/i-want-to-create-two-types-user-panel-for-two-types-user

But a user is a user, you don't need separate tables, that's where Authorization comes in.

Authentication just means a login is required.

jlrdw left a reply on Need Help In Saving Invoice Data

Posting with ajax and jquery has been covered so many times on this forum probably hundreds. I've given numerous examples myself.

Google:

site:laracasts.com ajax post
or
site:laracasts.com jquery ajax post

jlrdw left a reply on How To Remove All Of My User Caches?

Good one to know.

jlrdw left a reply on How To Write Standard Code?

Confused as to question, why not just follow the PSR coding specs. Which is what laravel follows.

jlrdw left a reply on Why Doesn't Laravel Use Joins When Pulling BelongsTo Or HasOne

The one extra query to get parent (master) is no big deal even if millions of users.

A join has to transverse over two tables.

You might want to take a basic sql tutorial. Or study the various selects, joins, etc here.

https://dev.mysql.com/doc/refman/8.0/en/

Again it depends on what data you need and how needed.

jlrdw left a reply on Laravel Saved File To Wrong Directory

If you go to

yourtsite.com/laravel

replace yoursite.com with actual name you should see:

jlrdw left a reply on Laravel Saved File To Wrong Directory

See what happens if you rename the folder that's above public_html to laravelup

And changing the lines to

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/../../laravelup/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../../laravelup/bootstrap/app.php';

And your index.php goes

|- public_html
    |- laravel
         |- index.php   // here
         |-  css
         |-  js

jlrdw left a reply on Laravel Saved File To Wrong Directory

You do have a RewriteBase in your htaccess.

You did point to main laravel with

../../

You should not be able to see the folder structure.

jlrdw left a reply on Laravel DB::query To Eloquent

Let's be realistic if that complex query is already working just use as is.

There are times to use the orm and times that it's not as good.

Direct relations is better suited for orm.

jlrdw left a reply on Laravel Saved File To Wrong Directory

If storing to a folder above public_html you setup a symbolic link:

https://laravel.com/docs/5.8/filesystem

Or many times on shared hosting you can upload to a folder underneath public_html.

jlrdw left a reply on Why Doesn't Laravel Use Joins When Pulling BelongsTo Or HasOne

You're overthinking this there are two styles of doing this one is as you suggest the other is like a monthly report.

For example company A with their receivables Company B and their receivables Etc.

Join is used a lot with a group by for a different style of report.

The two query technique is more like an invoice with the order details. In other words a Master detail or parent-child relationship.

So it depends on what data you need and how you need it.

18 May
3 days ago

jlrdw left a reply on How To Update And Edit A Image In Laravel 5.8

@IRANKHOSRAVI - Just one question: In another post you had trouble uploading an image. Not edit, but upload.

So, did you ever get that working?

jlrdw left a reply on I Need Help.

Why not start here:

https://www.w3schools.com/php7/ Then take Jeffrey's free courses.

jlrdw left a reply on Deploying Laravel App On Cpanel Shared Account

when i ssh any php artisan command from terminal on my mac, i'm getting this error...

So your host is fine the problem is on your Mac in your development version.

jlrdw left a reply on Deploying Laravel App On Cpanel Shared Account

If you go to your site and put in

Yoursite.com/.env

Of course replacing Yoursite.com with your site's actual name.

What do you get.

jlrdw left a reply on Having A Very Rough Time Learning Laravel

I would suggest just taking it slow and easy and realize like anyting there's a learning curve involved.

And practice by doing a small crud application.

There's quite a bit to be learned just working the examples in the documentation also.

jlrdw left a reply on Deploying Laravel App On Cpanel Shared Account

Main laravel goes above public_html see

https://laracasts.com/discuss/channels/laravel/next-issue-fonts-and-images-arent-visible

The guide in that link is from snapey, it works correctly.

Otherwise your site is insecure.

17 May
4 days ago

jlrdw left a reply on How To Create Two Columns With @foreach?

@SNAPEY - If you mean allows code to be executed repeatedly, and matched with the OP, I am following your advice.

jlrdw left a reply on What Is The Best Approach For Data Visibility Restriction? (guest,members,subscribers)

@AP3TWE - Well I don't do that, but post here, even if I can't help @snapey and @cronix And @bobbybouwmann and @others are very good with laravel.

Me I came from Java at first and I usually don't write everything like Taylor might. But I've been doing this sice ild dbase 3 in the late 1980's.

Example I use laravel authentication, but have custom helpers to work with that. But I know how to implement RBAC. Iwas even a contributor to another framework.

I do not suggest someone new to write custom helpers, services until they have quite a bit of experience.

Understand when I did java, servlets, jsp, and ejb, there wasn't "out of box stuff". Back then you even wrote your own paginator as example.

And I only did business programming, I did logistics programming at a trucking / loistics company.

I am very "old" school. But I do enjoy trying to help folks. I am semi retired now.

jlrdw left a reply on How To Create Two Columns With @foreach?

In controller do this:

public function index()
{
    $slideshows = Slideshow::latest()->get();
    $services = Service::latest()->get();
    echo '<pre>';
        print_r($services);
        echo '</pre>';
        exit();
    $faqs = Faq::latest()->get();
    return view('Home.index', compact('slideshows', 'services', 'faqs'));
}

I can view a print_r much better than a var_dump. You need to study the exact results you are getting.

jlrdw left a reply on Can't Login Using Custom Field

In your LoginController add:

    public function username()
    {
        return 'hd_username';
    }

And I am not 100% sure on the, but if that don't work try


Not in the construct function .

And change the forms as well.

jlrdw left a reply on What Is The Best Approach For Data Visibility Restriction? (guest,members,subscribers)

I like query scopes, to fine tune things right in the query:

    public function scopegetPets($query, $petsearch = '')
    {
        $petsearch = $petsearch . "%";
        $query->where('petname', 'like', $petsearch);
        if (ChkAuth::userRole('admin') === false) {  // custom RBAC
            $userid = Auth::user()->id;
            $query->where('ownerid', '=', $userid);
        }
        $results = $query->orderBy('petname', 'asc')->paginate(5);
        return $results;
    }

Not a spatie example but just example of, if user is an admin they can see all, otherwise

the query only allows a user to see their own data.

Many times roles and permissions are used in conjunction with the way the query s written.

The above I have a custom helper class that works with laravel authentication.

But example was to show how a scope is helpful.

jlrdw left a reply on Someone's Trying To XSS Us With Img Src=x Onerror=prompt(1)

Also to play it extra safe I usually run request through strip_tags.

Something like:

   public static function fixValue($rvalue)
    {
        $rvalue = empty($rvalue) && !is_numeric($rvalue) ? NULL : trim(strip_tags($rvalue));
        return $rvalue;
    }

Not saying to use a static helper like me, use a getter setter or whatever.

It removes those dangerous tags.

jlrdw left a reply on Simple Use Of Eloquent Join

Thanks for the code share.