harryg

harryg

Member Since 4 Years Ago

London

Experience Points 19,890
Experience Level 4

110 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 375
Lessons
Completed
Best Reply Awards 11
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.

12 Sep
2 years ago

harryg left a reply on Asynchronously Update A Model From A 'saved' Event

@rikh Wouldn't the instance of $address passed to the saved event always be clean by virtue of it having been persisted to the database? If so isDirty() would always return false, unless it is the pre-saved instance.

If not then that's also a nice solution, but I wasn't sure about the interpretation of isDirty for the saved model event.

11 Sep
2 years ago

harryg left a reply on Asynchronously Update A Model From A 'saved' Event

@luddinus That's a pretty good solution.

harryg started a new conversation Asynchronously Update A Model From A 'saved' Event

I have the case where when an address in my app is created or updated, I want to geocode it. I use a 3rd party service for the geocoding so ideally this job would be performed asynchronously via a queued job so I can provide feedback to the user quickly and not fail the request if the geocoding service is down or failing. It's not important that the address has been geocoded by the next page.

So I have set up an event listener to dispatch the job every time an Address is created or updated:

\App\Address::saved(function($address) {
    dispatch(new \App\Jobs\GeocodeAddress($address));
});

In my job's handle method I simply query the api and update the Address:

public function handle(Geocoder $geocoder)
{
    $location = $geocoder->getCoordinates($this->address);

    $this->address->update([
        'lat' => $location->lat,
        'lng' => $location->lng,
        ]);
}

The problem with this approach is that it fires the saved event again which causes the same job to be dispatched thus causing an infinite loop of doom where I DDoD attack the geocoding service and cripple my database.

I could just use the saving event and simply set the values there but that would not allow me to do the geocoding asynchronously.

Can anyone suggest an elegant way to do this?

01 Jul
2 years ago

harryg left a reply on Generating Secure Routes On Heroku With Cloudflare Ssl

Yes I server vars contain all the x-forwarded-* headers but still doesn't work properly. I tried forcing https on the laravel app which works until you get redirected. Then it thinks it's on *.heroku.com and you get an SSL error.

30 Jun
2 years ago

harryg left a reply on Generating Secure Routes On Heroku With Cloudflare Ssl

I'm actually using nginx but can easily change to Apache2 by editing my Heroku buildpack. I'm not sure exactly how to install mod_cloudflare on Heroku however. Their docs do not seem to say how to add apache modules.

harryg started a new conversation Generating Secure Routes On Heroku With Cloudflare Ssl

I have a Laravel 5.2 app running on Heroku and have set up a custom domain. I am also taking advantage of free SSL offered by Cloudflare. This is described in this official Cloudflare guide. It works fully because Heroku offer ssl by default for *.heroku.com.

The problem I'm having is that routes generated by the route() helper function, or the FormHelper route array key (Form::open(['route' => 'foo'])) are not generating https urls. The domain however is correctly using my custom one rather than the heroku one. I'm not sure of the cause of this but it seems Laravel thinks the request is somehow http rather than https, even though Cloudflare is set to use full SSL.

Has anyone got any experience of using Cloudflare and Heroku in this way and how to solve it, aside from hardcoding relative URLs in the views?

10 May
2 years ago

harryg left a reply on Just A Thought Models, Migrations, Factory

It's a bad idea for migrations as you often add more migrations as your app evolves. A migration isn't a state, as it would have to be if it resided in your model; it's a series of events that perform some modification to your database. Your deployed app should be able to run a migration from a recent feature addition even though it has already run the migrations up to that point. That's why you timestamp each migration file and Laravel keeps track of what's been run. This would be hard to implement and result in a bloated class if it existed in the model.

15 Apr
2 years ago

harryg left a reply on Page Slugs And Nesting

@MikeHopley Oh sorry, yeah I merged the branch in and deleted it. Have updated the links to the dev branch so should be working now.

14 Apr
2 years ago

harryg started a new conversation Develop Front End Theme As Separate Package From App

I have built a simple cms/ecommerce app in Laravel. Currently the front end consists of a set of blade templates in the resources/views/ directory and js/css assets which are compiled with Laravel elixir and saved in the public directory.

I'm trying to find the best way to enable overriding the default app templates with my own whilst falling back to the defaults if such a template doesn't exist. I'd also like a way to publish my custom theme's assets to the public directory so they can be used.

For best organisation any custom theme would exist as a separate package that composer would save in the vendor dir. I guess a service provider would register the templates and enable asset publication.

Hope can I start developing such a package without messing up my app's git repository?

13 Apr
2 years ago

harryg left a reply on Page Slugs And Nesting

@MikeHopley I have done some further refactoring. I'll post a link my repo tomorrow in case you want to review.

A good way to make use of the queues is to synchronously recalculate the page you're editing's url path, but delegate the child pages to a queue as it probably doesn't matter that they're not up to date on page refresh - you're only interested in the current page's attributes.

You also need to account for when a slug is changed as recalculate then as well.

Need to write a few more tests and tidy up but I think I've got something pretty elegant.

harryg left a reply on Page Slugs And Nesting

OK I've implemented having the path column in my pages table which removes the need for the complex recursive query to get the page from a set of slugs.

In terms of ensuring a page's path is always correct I made a job to handle the moved and created events. So in a service provider I do this:

public function boot()
{
    Page::moved(function($page) {
        dispatch(new \App\Jobs\UpdatePagePath($page));
    });

    Page::created(function($page) {
        dispatch(new \App\Jobs\UpdatePagePath($page));
    });
}

I don't yet make use of breadcrumbs but I could easily derive a set by exploding the path to get each slug in the trail. You need to dispath the job for both events as a page is not moved when it's created.

The job itself looks like this:

class UpdatePagePath extends Job
{
    private $page;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Page $page)
    {
        $this->page = $page;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $this->setPath($this->page);
    }

    /**
     * Re-calculate the path of the page and recursively update the pages of children
     * 
     * @return void
     */
    private function setPath(Page $page)
    {
        $page->update(['path' => $page->getPath()]);

        $page->getImmediateDescendants()->map(function($page) {
            $this->setPath($page);
        });
    }
}

This is a recursive operation as if you move a page in the tree, the paths of each descendant page will also change. Thus I might consider making this a queued job to improve admin panel speed for pages with many children but as you say it's probably perfectly fast to do syncronously in most cases.

A nice set of integration tests ensure everything works as expected.

harryg left a reply on Page Slugs And Nesting

@MikeHopley That is a nice approach. You'll certainly save sql statements by storing the permalink on save and update, although you must remember to regenerate it whenever this happens, as well as save a redirect (well suited to a queued job!). I suppose you listen for create/delete/update model events to fire this logic off.

Regarding redirects, how is it avoiding conflicts? I.e. you change the location of a page and create a new page in its place. Won't a redirect mean that the original page will get loaded first or do you check the pages table before applying a redirect? Either way I imagine it can get a bit complex - I'm gonna skip the redirects for now! Good reason to have decent integration tests.

12 Apr
2 years ago

harryg left a reply on Page Slugs And Nesting

OK I'm trying to implement this myself. The first step I take is to use the nested set package Baum.

Once installed ensure your model extends the Baum\Node and you have your migrations etc.

I have a route, which is the last route in my routes file so it doesn't get matched before more specific routes files like this:

Route::get('{slug1}/{slug2?}/{slug3?}', 'PagesController@show');

Currently it supports 3 levels of nesting but you can just add more optional parameters to achieve the max nesting level you want.

Next, implement the show method:

// PagesController.php
public function show()
{
    $slugs = collect(func_get_args());

    $page = $slugs->reduce(function($page, $slug) {
        if ($page->isLeaf()) {
            return $page;
        }
        return ($page->children()->where('slug', $slug)->first());
    }, Page::whereSlug($slugs->shift())->with('children')->first());

    abort_if(!$page, 404);

    return view('pages.single-page', compact('page'));
}

Now, this is not optimal as it performs an extra query for each level of nesting. You could cache this but it would be great to have a more efficient method.

Finally, in order to derive the permalink for a given page I added the following method to my Page model:

public function getPermalink()
{
    return $this->ancestorsAndSelf()->pluck('slug')->implode('/');
}

This will extract all the parents up the heirachy and get connect the slugs together. This is where the Baum package is great as it only takes 1 query for this, no matter how deep the page.

Still need to implement the functionality for organising pages but it should be pretty much acheivable with Baum by just using the makeChildOf($otherNode) method (or makeRoot()).

Any further suggestions welcome, especially with regards to deriving the page from a set of slugs.

11 Apr
2 years ago

harryg left a reply on Event Sourcing

+1 to this. For the uninitiated this talk by Greg Young gives a great explanation of event sourcing and CQRS and the reasons behind using it.

01 Apr
2 years ago

harryg left a reply on Env Variables To Controller

I'd advise not referencing environmant variables from anywhere but your config files. So in your case there is already a "mail from" config value (config/mail.php) which can be accessed with config('mail.from') and returns an array like so: ['address' => null, 'name' => null]

You can define the value of this in the config file with the env() helper rather than reference it directly. This keeps all your environment references in the same place for better organisation and also is necessary for config caching which greatly speeds up loading of configuration values.

31 Mar
2 years ago

harryg started a new conversation Generating PDF Reports With Charts

I want to build a reporting service that can produce a pdf report consisting of a basic template and also feature charts.

The idea I have is to use a blade view template and render it into a pdf using something like Laravel Snappy. I am aware of charting libraries such as chart.js which are nice-looking and easy to use. However, they rely on javascript to render the charts which does not play nice with server-side pdf renderers. I reckon the best approach is if the chart be rendered as an svg which can be styled accordingly. There is the chartist library which produces stylable svg output but it too is client-side.

Can anyone suggest a nice server-side solution to producing a pdf report from an html template containing charts, or at least a reliable way to render javascript-generated charts?

24 Feb
3 years ago

harryg left a reply on Fresh Install Laravel 5.2 - Problems With Testing

You've overridden the setUp() method in Laravel's testcase. Add parent::setUp() to your setUp() method of remove it and create the menu elsewhere.

15 Feb
3 years ago

harryg left a reply on How Are We All Displaying Alerts?

Currently just plain old dismissable bootstrap alerts.

09 Feb
3 years ago

harryg left a reply on Why Laravel Doesn't Use `extends Eloquent` By Default?

@Let Eloquent is and was never a facade. It was simply an alias to the full Illuminate\Database\Eloquent\Model class. It was aliased in 4.x presumably to avoid class name conflicts as models weren't namespaced by default.

In 5.x everything is namespaced so there's no need to alias the Model class, just use it directly. The Eloquent alias has now been removed from config/app.php as a result.

08 Feb
3 years ago

harryg left a reply on The COUNT Function In SELECT Statement

It sounds like you might just rather use the query builder then rather than hack an eloquent query. See https://laravel.com/docs/5.2/queries#joins. You should be able to use raw statements then.

Basically reference the DB facade instead of your eloquent model and specify the table and joins before selecting your fields.

Basically just modify your original query to be like:

$info = DB::table('article')
                ->leftJoin('comment', 'article.id', '=', 'comment.article_id')
                ->leftJoin('user', 'user.id', '=', 'article.user_id')
                ->groupBy('article.id')
                ->select(   // Article's ID
                    'article.id',  
                    // Article's Title
                    'article.title',
                    // ID of Article's Category
                    'article.category_id as cid',
                    // Author's ID
                    'article.user_id as uid',
                    // Summary count of all Views
                    'article.views',
                    // Creation's Time
                    'article.created_at',
                    // Author's Nickname
                    'user.username',
                    // Comment's Count
                    DB::raw('count(comment.article_id) as count')
                )
                ->orderBy('article.id', 'desc')->get()
            ));

harryg left a reply on Looking For A Search Engine Package

@giwrgos The Elasticsearch subscription is for a hosted service/support. You are free to download and run Elasticsearch on your own servers. The JRE isn't a big deal to run on your server.

harryg left a reply on The COUNT Function In SELECT Statement

As a side note, your table naming is unconventional which may be the cause of your errors. You are already using eloquent even without my previous suggestions and it assumes a convention unless you tell it otherwise.

I.e. Your Article model should have a table articles (whereas your table looks to be article - singular). Likewise with the comment table.

Model names should be CamelCase singular whilst tables names should be snake_case plural. You can of course do it your own way but I find it often easier to stick to convention.

harryg left a reply on The COUNT Function In SELECT Statement

@FewG You can still use an eloquent query with Twig. Just do something like:

$info = Article::with('comments')->orderBy('id', 'DESC')->get();

Pass $info to your twig view and you can iterate the collection however you like. Even if you don't want to you can still do $info->toArray() to just get an array. E.g.

echo count($info[0]['comments']);

Although it's easier just to use eloquent.

07 Feb
3 years ago

harryg left a reply on The COUNT Function In SELECT Statement

Why not just use eloquent?

If your Article model has a relationship set up:

// Article.php

public function comments()
{
    return $this->hasMany('Comment');
}

Then something like:

foreach (Article::all() as $article) {
    echo $article->title;
    echo $article->comments->count();
}
05 Feb
3 years ago

harryg left a reply on Why Does Envoyer Need To Restart PHP FPM When Deploying?

It's because your new deployment is created in a different directory to the one currently being served by php. The release is symlinked from the directory specified in the nginx config.

In order for php to load the new deployment it must be restarted so it follows the updated symlink in your project folder.

01 Feb
3 years ago

harryg left a reply on Deleting Model Isn't Working

The select() constraint in your eloquent query means it doesn't return the complete model but a representation containing only those fields you selected. As you are deleting the model there is no need to limit your query to just a few fields. Try:

$token = Token::where('token', $request->token)->firstorFail();
$token->delete();
28 Jan
3 years ago

harryg left a reply on Elastic Search

@phpMick sure but you will still need to keep your Elastic collections up to date with your DB so will probably want to use some model observers to do this.

In terms of searching - I'm not sure about Elastic being public-facing. You'll probably want to build some sort of api wrapper to perform your searches that queries Elastic server-side and returns a json response to the client.

13 Jan
3 years ago

harryg left a reply on Authenticating Ajax Requests Whilst Logged In

It turns out I needed to enable the following middleware on my 'api' middleware group:

\Illuminate\Cookie\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
\Illuminate\Session\Middleware\StartSession::class,

harryg started a new conversation Authenticating Ajax Requests Whilst Logged In

I'm logged in to my laravel site and I'm on a page which has the auth middleware applied to it. This page has some javascript which fires off an ajax request to an endpoint on the same laravel app but which also uses the auth middleware.

The ajax response is 401 Unauthorized. Why is this? Can't the auth middleware figure out that the ajax request is coming from a logged in session? How can I make this work without having to implement some complex Oauth system. These ajax requests will only be made from authenticated sessions.

12 Jan
3 years ago

harryg left a reply on Listening For Eloquent Model Events To Flush Cache Tags

So I've implemented this is my current project. I set the cache tags through some simple repositories using the decorator pattern (v useful for keeping your caching logic separate from your Eloquent logic), although I would only use repositories for data retrieval, not database writes (that's what eloquent's for).

So far all seems to work well. I was slightly concerned about encapsulating this logic into every page request. Does adding it to the model boot methods instead use less resources? Any feedback on this approach is appreciated.

11 Jan
3 years ago

harryg started a new conversation Listening For Eloquent Model Events To Flush Cache Tags

Say I have a caching convention which tags all cache entries related to a Post with "posts" (the table name of the Post model).

I want to devise a system that flushes the appropriate cache tag every time a Post is created, changed, deleted etc.

I know that eloquent fires various model events which you can listen for in a service provider or model's boot method, but I want a way of easily defining this funcitonality for multiple difference models, e.g. Post, User, Comment etc. E.g. either with a trait or in a service provider via, say, an array of "cachable" model class name.

Has anyone done anything like this yet?

07 Jan
3 years ago

harryg left a reply on Integration Testing Soft Deletes

The best solution I've come up with is just to refresh the user model and count the addresses. This doesn't verify that the address is no longer present on the addresses index page but does check that the address has been deleted. Here is my test:

    /** @test **/
    public function it_deletes_an_address()
    {
        $user = $this->loginWithUser();
        $address = factory(Address::class)->create([
                               'user_id' => $user->id,
                               ]);

        $this->assertCount(1, $user->fresh()->addresses);

        $this->visit('account/addresses')
             ->see($address->postcode)
             ->press('Delete')
             ->seePageIs('account/addresses')
             ->see('Address Deleted');
             //->dontSee($address->postcode);

        $this->assertCount(0, $user->fresh()->addresses);
    }
05 Jan
3 years ago

harryg left a reply on Integration Testing Soft Deletes

@llhilton no that is not the case - the postcode is definately showing up where it shouldn't. PHPUnit shows the output in the terminal when a see assertion fails and I have inspected it.

I understand the reason for this, just not how to solve it without directly checking the database.

harryg started a new conversation Binding An Instance Of A Class Into The Service Container

Say I want to use the Omnipay php library in my Laravel app. The docs say to use the basic usage is as follows:

// Create a gateway for the Stripe Gateway
// (routes to GatewayFactory::create)
$gateway = Omnipay::create('Stripe');
// Initialise the gateway
$gateway->initialize(array(
    'apiKey' => 'MyApiKey',
));
// Do a purchase transaction on the gateway
$transaction = $gateway->purchase(array(
    'amount'                   => '10.00',
    'currency'                 => 'USD',
    'card'                     => $card,
));
// etc

The thing is, the process of instantiating a Stripe version of Omnipay and setting the Api key is one which I'd like to avoid doing the controller.

Is this something I can do in a Service Provider and then just resolve it out of the IoC container. E.g.

// OrdersController.php

/**
 * Create a new order
 * @param  Gateway $gateway Some sort of Gateway implemention ???
 */
public function store(Gateway $gateway)
{
    // create the order, get card details etc...
    $gateway->purchase(
        //...
    );

    // etc
}

So my Gateway is automatically injected into the controller method as a Stripe instance with Api key already set.

How would my service provider do this?

harryg left a reply on Dynamic Eloquent Relationship

@haakym Ah OK, well you can still do this with the arrangement I've advised, you'll just need to form the correct query.

For the Report model you should have a course relationship as well as the student relationship. The id of the related course would be stored in the course_id field of the reports table.

// Report.php

public function course()
{
    return $this->belongsTo(Course::class);
}

Then on your student model you can query the latest report for their course like so:

// Student.php
public function latestReport()
{
    return $this->reports()
                            ->where('course_id', $this->course_id)
                            ->latest('date_to')
                            ->first();
}

This will limit your query only to reports related to the Student's course. Of course you will need to set these relationships when creating the reports.

harryg left a reply on Dynamic Eloquent Relationship

Well the date_to field is something that is common to all report types so this field would be on the base Report model and thus the reports table would have this field. You can then either define your latest report relation like so on the Student model:

public function latestReport()
{
    return $this->hasOne(Report::class)->latest('date_to');
}

You would then access a student report like so:

$student->latestReport->report; //gives the underlying report

You can also create methods on the parent report model to delegate down to the child reports to access their parameters without needing to specify the relation. E.g. a dynamic getter to get the sub-report's attribute if it doesn't exist on the parent report class.

harryg left a reply on Dynamic Eloquent Relationship

Polymorphism is the way to go. You would have a master Report model to which your student model would have the hasOne relationship with. This would have its own table. This Report model would then have its own polymorphic hasOne relationship to the sub-Report types; so the reports table would need reportable_id and reportable_type columns. You can then put any fields pertinent to a specific report type in the sub-report table e.g. phd_reports.

If this is unclear it's worth watching this vid by Adam Wathan where he does a similar thing with coupons: http://adamwathan.me/2015/09/03/pushing-polymorphism-to-the-database/

02 Jan
3 years ago

harryg left a reply on Integration Testing Soft Deletes

@desloc No, it doesn't pass as it's a soft deleting model - the record will still exist in the DB if soft-deleted.

I'm trying to check if it's being shown on a page showing a list of addresses (/account/addresses). This should work as Eloquent has a global query scope that exclude soft-deleted records (i.e. those that have their deleted_at time set). This isn't working in the test as I'm loading the addresses out of the User model and Laravel is not re-querying the records for the next request - it's using the one already loaded.

It works in the browser as the separate http request causes the current user's to be relations to be queried again.

harryg left a reply on Integration Testing Soft Deletes

@desloc nope, the address is fully built up from the Model Factory - I have faker generate the data randomly so there's no need to specify. The PHPUnit assertion explains what the failure is down to. E.g.

Failed asserting that <long html string>
' does not match PCRE pattern "/60542\-5066/i".

harryg started a new conversation Integration Testing Soft Deletes

I'm trying a simple integration test to test the delete process for a model (in this case an address. Here is the test:

/** @test **/
public function it_deletes_an_address()
{
    $user = $this->loginWithUser(); // logs in and returns the user model
    $address = factory(Address::class)->create([
                           'user_id' => $user->id,
                           ]);

    $this->visit("account/addresses")
         ->see($address->postcode)
         ->press('Delete')
         ->seePageIs("account/addresses")
         ->see("Address Deleted")
         ->dontSee($address->postcode);
}

The address model uses soft deletes. When I recreate the test in the browser it works fine but the test itself fails, saying it can still see the address postcode - the last assertion. It seems that although delete request works, as the test is a single process the user model in memory is the same and as such its addresses are not reloaded into it - not the same as if a real page reload. If I reload the user model with \App\User::find($user->id)->addresses I correctly get an empty collection.

Is there a better way to test this? I imagine it's common to test soft deleting models.

15 Dec
3 years ago

harryg left a reply on TokenMismatchException Webhook Issue

There are 2 ways I know of to disable middleware on a particular route/action:

  1. In the middleware class itself, if defining routes URLs to disable the middleware on you must use the $except_urls property:

    protected $except_urls = ['molliepayments/webhook' ];

  2. You can define the middleware on a particular controller action. I think is cleaner. In your PaymentController put something like the following in the constructor:

    class PaymentController extends Controller {
    public function __construct() { $this->middleware('VerifyCsrfToken', ['except' => ['webhook']]); } }

See http://laravel.com/docs/5.1/controllers#controller-middleware

10 Dec
3 years ago

harryg left a reply on NoSQL In Laravel

@jlrdw I'm not an expert at this but surely NoSQL must have some difference or it wouldn't exist. As I understand it it could allow one to have more flexible models as the database is less reliant on a schema. I.e. you can give your models attributes that don't exist in the table schema without having to change migrations.

I see there's a MongoDB package out there. It would be nice to see it in action and the basics of deploying a mongodb database.

Perhaps there's not enough here to justify a video but I thought it could be of interest. No worries either way.

03 Dec
3 years ago

harryg left a reply on Travis Build Errors Because Of Composer Dependency

Putting composer self-update in my build script for travis did the trick

harryg started a new conversation Travis Build Errors Because Of Composer Dependency

On my vagrant box all my tests pass and composer updates packages no problem.

When I push to github I have Travis run the tests in its environment. The build starts with a composer update to pull in my dependencies. This errors on all the builds giving my this error:

[RuntimeException]
Could not load package intervention/image in http://packagist.org: [UnexpectedValueException] Could not parse version constraint 4.x.x: Invalid version string "4.x.x"

I don't even have intervention/image as a dependency (although one of my other dependencies may require it). Nevertheless there is no problem installing in on my local vm so why is Travis having a problem.

The build itself can be seen here where you can view the whole console output as well as follow the link to the commit: https://travis-ci.org/harrygr/Creuset/jobs/94730366

17 Nov
3 years ago

harryg left a reply on What Kind Of Web Hosting I Would Need To Deploy Laravel And Php Websites ?

You'll want some kind of web server environment (not shared hosting) as you need to have the ability to install the dependencies and tools for easy deployment. A linux server is recommended although there's no reason why you couldn't get Laravel running on a Windows server (but I'd avoid it as I imagine many headaches). You'll need some level of knowledge of sysadmin and working on the command line over ssh but there are guides aplenty out there. A good way to learn is to set up a Homestead VM on your local PC and develop on that - it's an Ubuntu virtual machine that runs within your host OS.

If you want to avoid configuring servers almost completely you can go with Laravel Forge (https://forge.laravel.com/) which will provision your DigitalOcean or other server automatically and deploy your app from its git repo as well as other nice features. This will greatly cut down on your requirement for sysadmin skills.

Lastly, services like Amazon Elastic Beanstalk or Heroku can do a lot of provisioning for you and take a lot of grunt work out of a deployment.

09 Nov
3 years ago

harryg left a reply on Laravel 5.1, Free Shared Hosting

I doubt you'll be able to get Laravel running on your shared hosting. The specific problem is down to that function not being defined - in this case because the file defining it doesn't exists. Did you run composer install?

If if you get past this you'll have trouble on a shared host. Try something like Amazon AWS or Heroku which both have free tiers and are much more capable provided you learn how to work with them.

23 Oct
3 years ago

harryg left a reply on Update To Laravel Causing Tests To Fail With Error

OK, I've narrowed it down to phpunit itself. It seems anything > 5.0 causes testing to error. I've set my phpunit dependency to 5.0.*.