goatshark

goatshark

Member Since 4 Years Ago

Experience Points
62,825
Total
Experience

2,175 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
530
Lessons
Completed
Best Reply Awards
28
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 13
62,825 XP
16 May
4 months ago

goatshark left a reply on What's Wrong With This?

@artisticre Any progress? How's it going?

14 May
4 months ago

goatshark left a reply on What's Wrong With This?

It isn't that two URLs can't land you at the same place. It's that a single destination URL & verb ( /home and GET in this case ), can't be told to be handled by both the index() and dashboard() methods on the ManageController controller. That's like answering "how do I get to the hospital?" with two, different, and opposing, sets of instructions.

You are essentially saying that if a GET request comes in for /home, do something. In this case, that something is handled by [email protected].

Unfortunately, right after that, you are also saying that if a GET request comes in for /home to do something different...use [email protected].

So, unless I'm misunderstanding the confusion, you have to choose what you want to happen when you go to /home. Does that make sense?

goatshark left a reply on What's Wrong With This?

Hard to say. Depends on which does what you need when you point a browser to /home. Sorry, not trying to be cryptic, it just....depends.

Maybe change one of those two routes to /home1 and take a look at each in your browser.

goatshark left a reply on What's Wrong With This?

You have two GET routes for /home listed there. You'll hit the first one so [email protected] will be handling this up, not [email protected].

goatshark left a reply on What's Wrong With This?

Can you post the route for /home?

Also, does it point to the controller who's index() method is being discussed above? It kind of seems like it's not pointing there - if you've added a dd() in the index() method and the behavior did not change.

goatshark left a reply on What's Wrong With This?

Where exactly are you seeing this error?

goatshark left a reply on What's Wrong With This?

@artisticre Sorry, I missed the where statement the first time. So, you're looking for just one record anyway, so there's no real reason to be iterating over it. You probably do want to go back to using first() on there. My bad.

What do you see if you throw a dd($profilelist); in right after you set it (i.e. right before your return statement). That will let you know if you're actually getting the record you're looking for.

goatshark left a reply on What's Wrong With This?

@artisticre This might not be all that's wrong, but here:

$profilelist = DB::table('users')
  ->select('id','name', 'phone', 'email')
  ->where('id' '=' $userID)
  ->get()
  ->first()

You are requesting the first() record. So, while you might then have $profilelist->phone available (because you returned a single record that has a phone property), you won't be able to iterate over $profilelist as it is just one record. Perhaps try just dropping first() so you'll have a collection of profiles in $profilelist.

If you always need the phone number formatted in this way, you might consider playing with mutators on your model.

22 Jan
7 months ago

goatshark left a reply on Default Value For Nova Number Field

@Nakov I appreciate the heads up. I was wondering how it was going to perform in real life, which I'll be testing within the next couple of hours. If smoke or leprechauns come out of it, I'll be sure to update the thread. Thanks!

goatshark left a reply on Default Value For Nova Number Field

@Nakov Good call!! That seems to have worked. Thank you. I had tried playing with ->resolveUsing and ->displayUsing() to no avail. I went back to the Nova documentation regarding withMeta. Even after re-reading it, I still would not have thought that withMeta was going to get this done for me.

Thanks for the suggestion.

goatshark started a new conversation Default Value For Nova Number Field

Hello. I'm wondering if there’s a way to give this a default value.

Number::make('Quantity')->min(1)->max(1000)->step(1)

I feel like I’m missing something in the docs.

02 Jan
8 months ago

goatshark left a reply on 403 When Using Resource Controller

@bwrigley Can you post your web.php routes file?

27 Nov
9 months ago

goatshark left a reply on Multiple Laravel Site On One Vps

@jahstation This is where I reveal that I haven't used Apache in quite some time. That said, I think you still need your .htaccess but I can't speak to exactly what should be in it off the top of my head.

As for the virtual host config, I believe it would be best placed in /etc/apache2/sites-available/. You can name it something like site.conf where "site" is the name of the host you want to get to. The filename actually doesn't matter technically, but I try to match them up with my virtual hosts: somesite.conf, someothersite.conf, etc. I think it will end up looking something like this:

NameVirtualHost *:80
Listen 80
 
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName somesite.com
    ServerAlias www.somesite.com
    DocumentRoot /home/user/projects/laravel_project/public
     
    <Directory /home/user/projects/laravel_project/public/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
            Require all granted
    </Directory>
     
    LogLevel debug
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

After that's in place, you can sudo a2ensite somesite.conf.

Note that ServerName is what you need to resolve (either with DNS or the hosts file). Also note that the DocumentRoot is the path to the public folder in your Laravel project, not just the path to your project.

goatshark left a reply on Multiple Laravel Site On One Vps

If you have a single apache instance listening on a single IP that needs to serve multiple unique sites, that is name based virtual hosting.

So, Apache binds to one IP. Then, because of its virtual hosts configuration(s), when a browser asks for thissite.com, Apache serves files out of whatever directory is set to the root for the thissite.com virtual host. When a browser makes a request for thisothersite.com, Apache serves files out of a different directory, which is, again, configured in the virtual host configuration file(s) for thisothersite.com.

Does that help at all? At the end of the day, if you only have one IP address, you need name based virtual hosts of some sort set up in Apache to facilitate multiple websites.

goatshark left a reply on Eloquent BelongsTo() Returning Null

Alternatively, check out the "Default Models" section toward the bottom of https://laravel.com/docs/5.7/eloquent-relationships

I haven't utilized this yet, but it looks like it might be helpful in certain circumstances.

goatshark left a reply on Multiple Laravel Site On One Vps

@jahstation It sounds like you are looking for 'name based virtual hosting'. Check this out:

https://httpd.apache.org/docs/2.4/vhosts/name-based.html

goatshark left a reply on Eloquent BelongsTo() Returning Null

Like @staudenmeir was alluding to.... if you don't have a corresponding category record for the ID in the subject's category_id field, null is exactly what you should expect. If you grab a subject that has a valid category_id id, I think you'll be okay. Your relationship methods and your migrations look just fine.

goatshark left a reply on Eloquent BelongsTo() Returning Null

@ihassan Does your migration for the subjects table include an unsigned integer named 'category_id'? Also, how are you populating your data to test this? I.E. How are you creating categories and subjects when trying to determine if this is working?

22 Nov
9 months ago

goatshark left a reply on Multi-tenants App Vs API Clients

Multi-tenancy and the use of API clients are mutually exclusive. Multi-tenancy affects how your data is or is not separated from being accessed. Whether or not you are going to build an API and talk to it from your front end(s) is a completely different set of decisions.

21 Nov
10 months ago

goatshark left a reply on I Forget Test Methods

@tykus As a matter of fact, --testdox does exactly what I wanted. Good thing I like throwing away code, otherwise I might be miffed that I spent any time on that command. It was a nice exercise though. I haven't written many commands.

Thank you, @tykus, that's exactly what I was looking for.

goatshark started a new conversation I Forget Test Methods

Greetings,

I wrote an artisan command to compensate for my constantly losing sight of what test methods I've already written for a project. While I am certain this is wheel already exists, I couldn't find it in all the other wheels. ....I'm not even sure which wheel yard to look in actually.

Maybe someone can tell me which wheel I reinvented.

Btw, this should work, on it's own, dropped into app/Console/Commands.

<?php

namespace App\Console\Commands;

use App\TestFinder;
use Illuminate\Console\Command;

class FindTests extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'goat:list-tests';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'List methods starting with \'test_\' in test files ending in \'Test.php\'';

    /**
     * Path to test files
     * @var string
     */
    public $tests_path;

    /**
     * The suffix at the end of test file names
     * @var string
     */
    public $testfile_suffix = 'Test.php';

    /**
     * The prefix used on methods in tests
     * @var string
     */
    public $testmethod_prefix = 'test_';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();

        $this->tests_path = base_path('tests/Feature');
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $table_headers = ['Class', 'Tests'];

        $results = $this->getAll()->map(function($test_class, $key) {
            return [
                'class' => $test_class['class_name'],
                'tests' => implode("\n", $this->getTestMethods($test_class['class_name'])) . "\n"
            ];
        });

        $this->table($table_headers, $results);
    }

    /**
     * Create the whole dataset to return
     * @return collection
     */
    protected function getAll()
    {
        $all_classes_with_their_methods = collect();

        $this->getTestClassesWithFullPaths()->each(function($fq_class_name, $key) use ($all_classes_with_their_methods) {
            $all_classes_with_their_methods->push(collect([
                'class_name' => $fq_class_name,
                'methods' => $this->getTestMethods($fq_class_name)
            ]));
        });

        return $all_classes_with_their_methods;
    }

    /**
     * Get all test classes with paths
     * @return collection
     */
    protected function getTestClassesWithFullPaths()
    {
        $test_classes = $this->getTestFiles()->map(function($filename, $key) {
            return 'Tests\Feature\' . str_before($filename, '.php');
        });

        return $test_classes;
    }

    /**
     * Filter out any filenames that don't end with $this->testfile_suffix
     * @return collection
     */
    protected function getTestFiles()
    {
        $test_files = $this->scanDir()->filter(function($filename, $key) {
            return ends_with($filename, $this->testfile_suffix);
        });

        return $test_files;
    }

    /**
     * Filter all the methods to grab just the ones that start with test_
     *
     * @param  string $class_name Class name with path
     * @return array
     */
    protected function getTestMethods($class_name)
    {
        $test_methods = collect(get_class_methods(new $class_name))->filter(function($method, $key) {
            return starts_with($method, $this->testmethod_prefix);
        });

        return $test_methods->toArray() ?: ['no tests'];
    }

    /**
     * This is a raw scandir, so you'll get "." and ".." along with
     * every other file in $this->tests_path;
     *
     * @return collection List of files and directories
     */
    protected function scanDir()
    {
        return collect(scandir($this->tests_path));
    }
}
16 Nov
10 months ago

goatshark left a reply on Docker, Laravel And A Production Server With Apache Running

@alessandrobelli docker and docker-compose are installed separately; two different packages. That's why their version numbers are so wildly different.

Good luck with your docker project.

15 Nov
10 months ago

goatshark left a reply on One To Many, If 0 "Many", Delete The One

The only thing cascading onDelete will do for you is delete child hasMany records when you delete their parent. So, deleting $var will delete all $var->tableBs. I was just thinking that if you were cascading onDelete, you could skip removing that last $var->tableB relationship and instead just delete $var.

goatshark left a reply on One To Many, If 0 "Many", Delete The One

That would $var->delete(); regardless of what your count was.

Are you cascading onDelete? If you are, and if the count is 1, then you can just delete $var.

Alternatively, you could....

$var = TableA::find($id);

if ($var->tableB->count() == 1) {
   $var->tableB()->delete();
   $var->delete();
}

That is, if I'm understanding correctly that you want to delete the record from tableA when you're removing it's last/only relationship to tableB.

goatshark left a reply on One To Many, If 0 "Many", Delete The One

@jerauf You could get a count on your first query like $tableA->tableBs->count(). If it equals 1 when you start, you'll know to remove the record in table A after you remove the record from table B. Actually, if you are cascading onDelete, you could at that point skip removing the record from table B and just remove the table A record altogether.

13 Nov
10 months ago

goatshark left a reply on Docker, Laravel And A Production Server With Apache Running

@alessandrobelli I wouldn't call this "comprehensive", but I've been working on this and using it (in it's incomplete state) for a while.... https://github.com/goatatwork/LaravelDocker

Maybe it'll give you some ideas. Btw, I recently swapped out the php7.0 container for a php7.2 container. If I hadn't have been sold on containers before then (I was), I would have been when I did NOT have to deal with upgrading php on the OS. Wow.

12 Nov
10 months ago

goatshark left a reply on Dockerizing The Recurring Jobs Runtime

@Breki I'm unclear about how much of the application is needed to run scheduled jobs. Here's how I've been doing it in Docker.

With my project, I run a cron container. My Dockerfile is here:

FROM ubuntu:18.04

LABEL maintainer="goat <[email protected]>"

RUN apt-get update
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y \
    curl unzip zip software-properties-common iputils-ping \
    php7.2 php7.2-cli php7.2-mysql php7.2-gd php7.2-curl php7.2-xml php7.2-bz2 php7.2-mbstring php7.2-zip

RUN apt-get install -y --no-install-recommends cron nano mysql-client \
    && apt-get clean; rm -rf /var/lib/apt/lists/ /tmp/ /var/tmp/ /usr/share/doc/

COPY crontab /etc/crontab

COPY script.sh /script.sh

RUN chmod +x /script.sh

CMD ["cron", "-f"]

I know that I could swap this out for a container originating (FROM) from something like php:7.2-fpm-stretch, but I haven't done that yet. This is working though.

Two additional files, crontab and script.sh.

crontab

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

* * * * * root /script.sh > /proc/1/fd/1 2>/proc/1/fd/2

script.sh

/usr/bin/php /var/www/html/artisan schedule:run

I run this in my docker-compose.yml like so:

  cron:
    build:
      context: ./docker/cron
      dockerfile: Dockerfile
    image: ${BASE_TAG:-laravel}/cron:production
    volumes:
      - ./:/var/www/html
      - /tmp:/tmp

So, I'm mounting my project's source directory as /var/www/html. I can't quite remember why I mounted /tmp to '/tmp`, but I'm sure it was necessary for cron while getting this working.

With this setup, as long as the cron container is running, then script.sh is run every minute and therefore php artisan schedule:run is run every minute. At this point, it's back to all Laravel.

I know there are a ton of different ways to get things done using containers. If this doesn't get you to where you want to go, I hope it at least gives you some ideas for your project.

07 Nov
10 months ago

goatshark left a reply on How To Access Files From Blade In My Storage Directory?

@martinzeltin Nice. And if you don't want to manually link it, I believe that's exactly what php artisan storage:link does. Glad you got it figured out.

goatshark left a reply on How To Access Files From Blade In My Storage Directory?

@martinzeltin Take a look at public_path(). It might be more what you are looking for. Also, I review https://laravel.com/docs/5.7/filesystem#the-public-disk every time I'm dealing with this topic.

31 Oct
10 months ago

goatshark left a reply on Laravel Mail Doesnt Work On Production.

@martin182, are you able to connect to that host and port via telnet? That will lead you to whether or not this issue is with your Laravel application or with communication between your production server and the mail server.

goatshark left a reply on Laravel Mail Doesnt Work On Production.

@martin182 Any chance your production box is behind a firewall that isn't allowing you to connect to the mail server? To test, you could try telnet'ing to smtp.office365.com at port 587 from your production box. That address and port work from here:

~ » telnet smtp.office365.com 587
220 DM6PR18CA0034.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 31 Oct 2018 13:25:08 +0000
quit
221 2.0.0 Service closing transmission channel
Connection closed by foreign host

goatshark left a reply on UserController:storeUserInfo: 1 Passed And Exactly 2 Expected

Hey @splendidkeen The two routes that you posted above:

Route::get('/user/{username}', '[email protected]')->name('partner.user.profile')->middleware('auth:partner');

Route::post('/user/info/create', '[email protected]')->name('partner.user.info.create')->middleware('auth:partner');

There is a {username} variable required for the get route, but not for the post route. Perhaps something like this will be good:

Route::post('/user/{username}/info/create', '[email protected]')->name('partner.user.info.create')->middleware('auth:partner');

goatshark left a reply on UserController:storeUserInfo: 1 Passed And Exactly 2 Expected

@splendidkeen A couple of things. In web.php, it looks like you have a space between [email protected] and storeUserInfo. Also, for that route, your URL is /user/info/create, but you are not sending a $username string in that URL like you are for your get route immediately above that. I believe that's where your missing $username should come from...the URL. Make sense?

29 Oct
10 months ago

goatshark left a reply on Laravel API Resource - How To Assign Sequence Number For Each Collection Item?

@TARASOVYCH If the only requirement/goal of sequence_number is that it be unique to user, I would use the id attribute already present on User. It is, by design, unique to that user.

If sequence_number can't use (or just be) the id on the User model, then I would ask what exactly is sequence_number intended to be used for, or at least, what logical parameters do you care about when creating sequence_number.

goatshark left a reply on How To Manage Your Global Vue Component?

@wilk_randall Real answer: because when I was learning to make anything work, I found that that worked to pull in components. What's the difference between these two? That's a 100%-non-snark, genuine question. What topic can I look up to read about the differences?

26 Oct
10 months ago

goatshark left a reply on How To Manage Your Global Vue Component?

@zerogpm Good point. Old habits die hard. I sometimes forget about that little nugget of ES6 magic. Thank you.

goatshark left a reply on How To Manage Your Global Vue Component?

I don't know if this is the suggested way of getting it done, but this is how I import my components into components...

<script>
    var SomeComponent = Vue.extend(require('./SomeComponent.vue'));

    export default {
        components: {
            'some-component': SomeComponent,
        },
25 Oct
10 months ago

goatshark left a reply on Queue Job - Execution Of Old Code

@jack100 Well that's frustrating AF. I know I've run into this before. I'll look through a few projects to see if I can find anything helpful.

goatshark left a reply on Changes In Laravel's Controller Not Work After Save

@fdjunior Okay or not okay, it certainly shouldn't be needed.

Have you run for a while making sure you're in an incognito (or equivalent for your browser) window. Browser cache has cost me more minutes than I'd like to count.

goatshark left a reply on Changes In Laravel's Controller Not Work After Save

@fdjunior When I run into things like this, I start dropping dd('oh shit'); lines generously...one a time though - I'm not completely nuts. You could even start by using it in a callback in the route you're trying to hit. I've done that when I felt that I needed a complete sanity check.

goatshark left a reply on Queue Job - Execution Of Old Code

Restarting supervisor is nice and I believe it results in the same outcome as php artisan queue:restart, but did you try php artisan queue:flush?

goatshark left a reply on Console Log Vue's Component Name

Hey @Gabotronix Maybe this:

console.log(this.$options.name+' component successfully mounted');

That way, this$options.name is outside of any quotes.

goatshark left a reply on Mapping Values In A Multi Dimensional Array

Hey @richard In your test, is there a chance that $newArray is empty? At first glance, considering your error, it seems like you're mapping through an empty array.

goatshark left a reply on Queue Job - Execution Of Old Code

@jack100 Are you running Horizon? Or are you just running some php artisan queue:work commands from cron?

Have you tried to php artisan queue:flush and php artisan queue:restart?

23 Oct
10 months ago

goatshark left a reply on Nginx Fail After Upgraded To Ubuntu 18.04

@ardnor I would start looking in /var/log/nginx. The log files being written to depend on the configuration, so you'll have to locate where the new errors are being written to. /var/log/syslog might give you some love, too.

goatshark left a reply on Fastest Way To Duplicate A ~9GB MySQL DB

In regards to bringing up that data in an 'environment' that you can use... I have recently found it extremely useful to start mysql containers while binding a directory containing my dump file as /docker-entrypoint-initdb.d.

docker run \
-e MYSQL_ROOT_PASSWORD=some-password \
-e MYSQL_DATABASE=some-db-name \
-e MYSQL_USER=admin \
-e MYSQL_PASSWORD=some-password \
-v "$(pwd)/db":/var/lib/mysql \
-v "$(pwd)/db-backup":/docker-entrypoint-initdb.d \
--name some-container-name \
-d mysql:5.7

This creates a database named some-db-name and populates it with the data from the dump file that I have ./db-backup.

That doesn't exactly answer your question, but maybe gives you some other angles to try.

YMMV, obviously.

goatshark left a reply on ParseError: Syntax Error, Unexpected 'public' (T_PUBLIC), Expecting ',' Or ';'

@Danieloplata Glad you found it. I am also always with the $fillable over $guarded.

goatshark left a reply on ParseError: Syntax Error, Unexpected 'public' (T_PUBLIC), Expecting ',' Or ';'

@Danieloplata Probably just a missing ;, but in your User::class or Thread::class. Your test looks good.

goatshark left a reply on Undefined Offset: 0 In Foreach Loop

@suhaskunte777 In the event that a Qnode does not have a Data, $item['datas'] will be empty, so no [0]. You could throw in a check to see if there's anything in $item['data'] before referencing $item['data'][0], or just get right to the point and check for the existence of $item['data'][0] itself.