steveperrycreative

Designer / Developer at Steve Perry Creative Limited

Hire Me

Experience

34,015

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 518 Lessons Completed
  • 8 Favorites

8th May, 2017

5th May, 2017

steveperrycreative left a reply on Ideas To Store Record Activity Logs? • 6 months ago

If you are talking about what I think you are talking about then Jeff just covered something like this in the Forum series:

https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/25

steveperrycreative left a reply on Static::deleting In A Boot Method Is Not Working In Test • 6 months ago

I should add that when I perform the task in a browser it works as expected so it is just the test that isn't working.

steveperrycreative started a new conversation Static::deleting In A Boot Method Is Not Working In Test • 6 months ago

This is my test:

    /** @test */
    public function deleting_a_task_from_a_project_restores_its_credits()
    {
        $this->signInAsAdmin();

        $project = factory('App\Project')->create();

        $task = factory('App\Task')->create([
            'project_id' => $project->id,
            'credits_used' => 20
        ]);

        $project->credits = 100;
        $project->save();

        $response = $this->json('DELETE', $task->path());

        $response->assertStatus(204);

        $this->assertTrue($project->credits == 120);
    }

My destroy method on the TasksController is:

public function destroy(Task $task)
    {
        $project = $task->project;

        $this->authorize('update', $project);

        $task->delete();

        if (request()->wantsJson()) {
            return response([], 204);
        }

        return redirect($project->path());
    }

And my boot method on the Task model is:

protected static function boot()
    {
        parent::boot();

        static::creating(function ($task) {
            $task->project->removeCredits($task->credits_used);
        });

        static::deleting(function ($task) {
            $task->project->addCredits($task->credits_used);
        });
    }

The add and remove credits methods just perform some basic maths and save, nothing fancy. When I test creating a task the credits get removed from the project as expected. However when I run the above delete test nothing happens to the credits on the project, they stay at 100.

The boot method runs fine. I've even tried sliming it by just doing:

    static::deleting(function ($task) {
        $task->project->credits = 120;
        $task->project->save();
    });

But that doesn't work either. I'm stumped. Am I missing something silly!?

21st April, 2017

steveperrycreative left a reply on How To Store Time, And Manipulate It -- Not Time Travel Related ;) • 7 months ago

@Snapey that's exactly why I posted here, to get a fresh perspective like that. Thinking of it as credits makes it much easier to get my head around it, thank you.

20th April, 2017

steveperrycreative left a reply on How To Store Time, And Manipulate It -- Not Time Travel Related ;) • 7 months ago

I have yes, thank you, and will be storing time as a Carbon instance but I'm unsure of where to store it. I.e. would it be better on the Task(s), Project or would it be better to have a Time model? Or something completely different.

steveperrycreative started a new conversation How To Store Time, And Manipulate It -- Not Time Travel Related ;) • 7 months ago

I'm re-writing an application for my business which helps me manage website maintenance plans for my clients.

These plans differ, depending upon what the client requires. Some are just software updates and some include discounted monthly hours of my time. Standard stuff.

I add projects to the application, which then have tasks added to them and I have a plan associated to the project. Those tasks, when added, subtract time from the client's accumulated balance of hours. The balance of hours should auto-accumulate each month based upon the associated plan.

To complicate matters a little, some of these plans have their hours reset after 3 months of accumulation, but not all of them.

Project views show all tasks (with time used on them), the current plan, accumulated hours and hours/mins remaining.

My question is how should I store this time so that I can retrieve it and manipulate where required. It would be nice if I could even retrieve the hours that have been reset (just for reports etc).

In the past I just stored a number which related to the number of hours allowed each month and did some basic maths when loading the views but this was obviously very restricted so I'm keen to hugely improve in v2.

Should I create a Time model? How would this work with a cron, which I guess I'll also need to keep the hours adding up in the background?

Any pointers really appreciated as I'm struggling to get my head around it a bit. I'm still relatively new to Laravel and OOP in general.

26th August, 2016

steveperrycreative left a reply on Warranty Period For Websites • 1 year ago

No at all @TheNephilim but I make sure that I communicate it well from the start. Most clients take out maintenance plans so it's not really an issue for them.

25th August, 2016

steveperrycreative left a reply on Warranty Period For Websites • 1 year ago

Personally I tell clients it's 30 days from launch and make it clear that it's wise to take out a maintenance plan. I'm a sucker for just fixing stuff like you mention though, after 30 days, and quite often get taken advantage of because I'm always keen to keep clients happy. It's fine as long as you keep a healthy balance and communicate well.

15th February, 2016

steveperrycreative left a reply on User Registration Email Confirmation Issue • 1 year ago

@schir1964 no the tut is using 5.1.*

14th February, 2016

steveperrycreative left a reply on User Registration Email Confirmation Issue • 1 year ago

Yep ok will do.

steveperrycreative started a new conversation User Registration Email Confirmation Issue • 1 year ago

I've been following this tutorial on adding user registration email confirmation but instead of creating my own registration controllers I'm using an amended version of Laravel's auth controllers, bringing it inline with Jeffrey's custom version.

However when a user registers I receive the following error:

ErrorException in AuthController.php line 67:
Argument 2 passed to Prolinked\Http\Controllers\Auth\AuthController::create() must be an instance of Prolinked\Mailers\AppMailer, none given, called in /Users/steve/Server/jasoncampbell/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php on line 59 and defined

Which I'd kind of expect but then Jeffery's version is the same and as far as I can tell his route isn't passing a 2nd argument through either but he is not getting this error. Am I missing something from somewhere else perhaps?

My AuthController is:

<?php

namespace Prolinked\Http\Controllers\Auth;

use Validator;
use Prolinked\User;
use Prolinked\Mailers\AppMailer;
use Prolinked\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'firstname' => 'required|max:255',
            'lastname' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @param  AppMailer  $mailer
     * @return User
     */
    protected function create(array $data, AppMailer $mailer)
    {
        $user = User::create([
            'firstname' => $data['firstname'],
            'lastname' => $data['lastname'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);

        $mailer->sendEmailConfirmationTo($user);

        flash('Please confirm your email address.');

        return redirect()->back();
    }

    /**
     * Listen for our user creation and add our token during that process.
     */
    public static function boot()
    {
        parent::boot();

        static::creating(function($user) {
            $user->token = str_random(30);
        });
    }
}

Let me know if you need to see any other code.

27th July, 2015

steveperrycreative left a reply on Problem Uploading File With Laravel Excel • 2 years ago

Fantastic, thank you! Worked a treat.

steveperrycreative started a new conversation Problem Uploading File With Laravel Excel • 2 years ago

I'm trying to upload a file and add the contents to my database using Laravel Excel. The file is uploaded using a form which posts to my uploadFromCsv method.

When I upload the file I get:

PHPExcel_Reader_Exception in Excel2007.php line 82: Could not open for reading! File does not exist.

My form is:

<form class="form-horizontal" method="POST" action="/ascents/upload">
    {!! csrf_field() !!}
    <div class="form-group">
        <label for="file" class="col-sm-3 control-label">Select CSV File</label>
        <div class="col-sm-9">
            <input type="file" class="form-control" id="file" name="file">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            <button type="submit" class="btn btn-default">Upload</button>
        </div>
    </div>
</form>

And my method is:

    public function uploadFromCsv()
    {
        Excel::load(Input::file('file'), function ($reader) {
            foreach ($reader as $log) {
                $ascent = new Ascent($log->all());
                Auth::user()->ascents()->save($ascent);
            }
        });
        return redirect(route('ascents'));
    }

21st July, 2015

steveperrycreative left a reply on PHP Books • 2 years ago

@polarcubs I think that is possibly one of the longest resource lists I've seen. Thanks for the recommendation.

Thanks everyone, I've started with @ian_h's and Jeffrey's recommendation of PHP Objects, Patterns, and Practice and will work through the rest. It's great so far, really easy to understand and very well written.

20th July, 2015

steveperrycreative left a reply on PHP Books • 2 years ago

Thanks, Ian. They don't have to be Laravel-specific.

steveperrycreative started a new conversation PHP Books • 2 years ago

I'm relatively new to object oriented PHP but I'm slowly beginning to understand the basic principles and I'm comfortable setting up basic classes, methods and putting them to use.

I'd like to start learning more about patterns, conventions and testing. I really enjoy the videos on here and would like some recommendations for some off-screen learning (books!) which are steady enough for a relative beginner.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.