miwal

miwal

Member Since 3 Years Ago

Uppsala

Experience Points
50,510
Total
Experience

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

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

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

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 11
50,510 XP
Sep
29
1 month ago
Activity icon

Replied to OK To Delete Migration File That You Subsequently Reversed, In A Running App?

the best answer to this question would also explain why. i have not yet looked at the source but will do so before i do this. except i'm in the middle of an upgrade so that's delayed for the time being.

Sep
26
1 month ago
Activity icon

Started a new Conversation OK To Delete Migration File That You Subsequently Reversed, In A Running App?

I'm refactoring a running app into packages and I notice quite a few migrations that were subsequently reversed. (e.g. something added then later identically removed). Even though the migrations table in the running app contains references to these as having been run, am I OK to delete migrations which I am certain were simply done then reversed later, (this is to keep the package code clean). I am FULLY aware of the general principle that the point of migrations is to only add them, not remove them; the question here is about evolving to a cleaner package within a running application without including migrations corresponding to redundant addition then removal of old irrelevant schemas.

My suspicion is this seems OK. Wondered if anyone has a view on this.

Sep
24
1 month ago
Activity icon

Replied to Regex Validation

Yes, i have that planned as second line of defence (or maybe first, you're right). Thought i'd try the regex first though. not quite done yet...

Activity icon

Replied to Regex Validation

I went down the path of instead of trying to exclude things (with a negative lookahead), say exactly what you do want.

^[a-zA-Z][a-z]*( [a-zA-Z][a-z]*)*$

matches all except the last:

HaMnOseEKoWu
aeBJxOcpiuSt
kcLQvMWjNBaD
John
bert
Bert Beck
John Albert Finney
joey smithe Jr
Joey Extra PhD

Any improvements or other suggestions appreciated...

Activity icon

Started a new Conversation Regex Validation

My site is being attacked by a bot which is registering lots of user accounts all with user names like:

HaMnOseEKoWu
aeBJxOcpiuSt
kcLQvMWjNBaD

Along with the obvious non-name above, it registers real looking but invented email addresses.

So I need a regex to add to the Validator in RegisterController which will reject these registration attempts. I thought no real name has a small letter followed by a large letter without a space, so could use that.

I'm investigating it now but would appreciate any suggestions. Can't recall how exactly to exclude characters in a regex. Thanks.

Aug
27
2 months ago
Activity icon

Replied to Add New Comment Syntax For Blade: ';;' ?

@snapey interesting... but isn't blade .blade.php, not .html? I realise this may be a rabbit hole though :)

Activity icon

Replied to Add New Comment Syntax For Blade: ';;' ?

Thanks @talinon, I already have a snippet. I have sublime set up pretty powerfully for laravel (& blade) already.

The issue I was concerned with is the visual clutter.

I've recently been doing lisp and am feeling the pain of blade in comparison... best wishes &thanks.

Activity icon

Replied to Redirect Back WithoutQueryParameters ?

So, in boot of a service provider, e.g. MonkeyPatchServiceProvider, I have this:

RedirectResponse::macro('withoutQuery', function() {
    return redirect()->to(explode('?', url()->previous())[0]);
});

which means my controller code now reads:

return back()->withoutQuery();

Works fine & dandy, but it'll take time to see if I like this or not. May prefer it in base controller class, and use monkey patches only for emergencies.

Activity icon

Replied to Redirect Back WithoutQueryParameters ?

The real answer to this which I was introduced to by reading Matt Stauffer's new edition seems to be what Taylor has christened "macros" in laravel (with sincere apologies to anyone who knows Lisp/Clojure - these have no relation whatsoever to the real concept of macros there, unchanged since the 1960s and one of the most wonderful things in all of computer science). In these laravel thingys, or I can say add-a-functions, you can add a new function onto an existing class, including the request, so this appears to achieve (by a shortcut) exactly what I was looking for here.

Amusingly, I have just done a search online to find out if there is an existing name for "adding a function to an existing class" . It turns out what this should have been called is Request::monkeyPatch('name-of-new-function', function() {... }) :) I guess that's why Taylor chose a more mysterious sounding name instead.

To see the other perspective, since this is within the context of a framework, this monkey patching isn't as bad as "real monkey patching", perhaps (indeed, it's potentially helpful here - remains to be seen) but I think it still would be more accurate and helpful to call it what it is, since this name already exists for this action. As it stood, I had read about these things in laravel before, but always had a kind of 'what is that' reaction, perhaps because of the strange name. Hopefully this time I'll remember if I actually need it again (only for exceptional cases, of course).

Even just Request::addFunction('name-of', function() { ... }) could have done the job re. naming there! Does anyone else use these?

Activity icon

Started a new Conversation Add New Comment Syntax For Blade: ';;' ?

Is it possible to add ;; as a new comment syntax for blade?

I'd like to be able to comment like this:

@if(Auth::user())
    ...
    ;; this is a comment and blade should ignore this up to EOL.
@endif

Blade's current 8, eight! characters for comments I find very verbose and is a big drawback in fluency compared to others I've seen, as comments are so frequently used.

I know there's a thing like 'blade extend' but not sure if you can do this. Yes, this would mean you can't write two semi-colons and have blade translate them to html, but I'm fine with that. Just an idea at the moment, wonder if anyone wants to run with it.

Activity icon

Replied to Redirect Back WithoutQueryParameters ?

I actually realised the helper function was an option before I read these replies. The way I prefer to add helpers is to use a class, import it and use statics, like MyApp::redirectBackWithoutQuery(). I saw @themsaid use that in his wonderful writingink/wink source code. He writes the framework so I figure copying his style is not a terrible idea.

To me it it's not too attractive to put these kind of things in individual controllers at this point, the moment you use it in more than one you've got code duplication (I am seeking to improve my style and get better at writing more maintainable code). So I've put it on the base controller class so can call $this->redirectBackWithoutQuery(). Not bad.

But may I ask the experts here out of curiosity (and in order to improve understanding of the abstraction options which are available) -- is it possible in any way to actually set things up so we can do return request()->back()->withoutQuery() ?

Can one override the Request class, if that's the right thing do achieve that, within Laravel and bind the new inherited class into the container instead? I have not mucked about with rebinding much yet.

A few tips/hints would be cool -- I'm happy to also go and research this myself too.

Thanks to all, especially to @cometads who solved this first and fast.

Update: reflecting on it further, I suppose there's a good argument that since you can easily add a global helper (so long as we're ok with that), then since that would let you do just return backWithoutQuery(), then one could argue what's the point of overriding the Request class even if it's possible... would be a fair point.

Update 2: I've gone with the global helper for now. One niggling doubt was/is, if global helpers in user land of the framework are a good idea, why does the framework not set that up for you? Maybe the answer is, I'm speculating here, is that if they are added they might be abused a bit or confuse beginners, and they are not hard to add if needed when someone with more experience knows they want them. I wonder what the general expert consensus on that is here, if that's approximately it. (as to why the decision appears to have been taken not to set up a file 'helpers.php' by default in the application skeleton laravel/laravel).

Update 3: I've changed my mind. The reason: putting this method on the controller base class seems a sufficient level of abstraction. I never (though one never knows the future) need this method outside of a controller. When I see a global, right now I know it's a framework global, so starting to add my own (viz., just for this) pays the price of changing that simple understanding. Yes with today's code editors you can just click through to see a function definition, but that just alleviates the cognition problem, that fact doesn't actually generate simplicity in itself.

Aug
26
2 months ago
Activity icon

Replied to Redirect Back WithoutQueryParameters ?

Super neat - that works, thanks.

However... I now realise my quest for this method was largely to get readable code... !

I know where I'm redirecting back to in this instance, and didn't want to redirect to the actual route name because that makes the intention in the controller less clear. "back without query params" states exactly what the code intends to do.

The regex is lovely but again maybe it's not very scannable/readable?... or maybe it is, its a nice tool of course.

I guess it's not possible to somehow be able to write ->withoutQueryParameters() since we probably can't or don't want to override the request class; or is anything like that possible neatly within laravel?

Activity icon

Started a new Conversation Redirect Back WithoutQueryParameters ?

I'm looking for a function which would do this:

redirect()->back()->withoutQueryParameters()

Specifically the back location may contain a query string ( e.g. ?something=somethingelse) appended to the url. I want to redirect back there with that bit removed, just to the base url.

I scanned the source for back() and couldn't see how.

Jun
15
5 months ago
Activity icon

Replied to How To Handle Laravel Eloquent "WHERE" Query With Slash On The Value? (Laravel 5.3)

Hi @Snapey, I started using Nova and find it uses 'App\\User' (i refer to the syntax of double slash) in the $model field. I've never used double slash before when writing model names as strings as far as I can remember, and nova also appears to work with single slash. I don't understand when to use double vs. single slash or if "either work" - is that something to do with eloquent doing something extra to let you use single slash whereas double is what we should be clear is the norm? App\\User::class is an error, so the double slash is when writing a string of course. What's the best method? Is it best to always use double slash when quoting a model as a string like 'App\\User'? Thanks a lot.

Jun
05
5 months ago
Activity icon

Replied to Configs Depending On Another Config

Here's one way to do it. I'm not sure if this is a really bad method or not though. Tentative steps...

In new file config/heroku.php:

function herokuapp_view_directory($herokuapp) {
    switch($herokuapp) {
        case 'my-app-instance-01':
            return 'dir1'; break;
        case 'my-app-instance-02':
            return 'dir2'; break;
    }
}


return [

    'app' => [
        'view' => [
            'directory' => herokuapp_view_directory(env('HEROKU_APP_NAME'))
        ]
    ]

];
Jun
04
5 months ago
Activity icon

Replied to Configs Depending On Another Config

A point I wanted to add here is that if we look at how Ghost blogging platform works, it achieves instance specific behaviour with zero configuration whatsoever. i.e., it's what's in the database, what content has been created, which completely determines instance behaviour.

e.g. if you have a rule like "you can create some pages, and you can give them an ordering" (note no configs here). If you do that, then a nav will appear on the welcome page with links to those pages in the order you gave them. No env vars in sight to do this, yet it's flexible, stemming solely from what content has been created.

But I'm thinking that won't cover every use case. Anyone care to share their experience that would be really great.

Activity icon

Started a new Conversation Configs Depending On Another Config

I'm exploring the options for running multiple instances of a single codebase where each instance needs some amount of separate configuration. One option would be to granularise everything and be as specific as possible, but that might get a bit unwieldy. I don't actually know yet whether that will happen. Another seems to be to use a single config just stating what instance it is that the code is running on, then deduce from that all the other settings that instance needs. The latter approach if my conception is correct basically means you store your configuration in code, not in environment vars. Whether that's better might mean which you will find easier to manage. In my case since deploying new code is costless, I might prefer that.

However, when I come to draft that, I want a new file in app/config/my-codebase-name.php

These files return arrays (and end up cached, not sure if that impacts the code that go in it at all).

Normally we write

'view' => [
   'directory' => env('VIEW_DIRECTORY')',
]

and access that with config('myapp.view.directory')

But what if I want to use config('myapp.instance.name') and switch the value of myapp.view.directory based on what myapp.instance.name happens to be?

This works:

'view' => [
  'directory' => (env('INSTANCE_NAME') == 'blg-01') ? 'mydir1' : 'mydir2';
]

But I want that to scale to about 10 instances. Can I / should I state that the value of that array key is the value of a switch statement? This seems unweildly and I don't even know if php would do it. I tried putting a switch/case statement as the array value (it didn't work, error 'unexpected switch'). i.e., obviously this is wrong

    'foo' => [
        'bar' => switch(env('APP_NAME')) {
                    case 'a':
                        '1';
                    break;
                    case 'b':
                    '2';
                    break;
                }
    ],

Maybe this is a question for stack overflow. Didn't get anything for "php expression as value of array" first look.

Please also critique how i've proposed solving this problem, not just making the method I describe above work. Thank you...

Activity icon

Started a new Conversation First Job Dispatched With App\Jobs\TestJob::dispatch() On Opening Tinker Is Always Lost?

I think I came across this before but can't find a reference to the reason. This is reproducible, horizon always looses the first job dispatched as above only when opening tinker for the first time. Would be good to know the reason... thanks.

Jun
02
5 months ago
Activity icon

Started a new Conversation Format Of 'AWS_URL' As Used In Config/filesystems?

Url parsing has just been added to config/database in the latest version of the framework source & app skeleton (laravel/laravel), so to run on heroku we no longer need to parse a single env in the form of a URL into a set of credentials, just add the 'url' parameter instead, which makes it faster set up than previously. (Parsing REDIS_URL seems in the works right now - may arrive working properly at some point soon).

My question though is in config/filesystems there's an AWS_URL. Currently I set three individual AWS env's, plus a bucket. AWS_URL implies the three individual settings can be compacted into the single url, just like for database & redis as above. The docs don't seem to mention this though.

What's the format of the AWS_URL and does this work reliably?

Benefit is it just means configs are tidied up (compacted) slightly.