bencarter78

bencarter78

Member Since 5 Years Ago

Nantwich, UK

Experience Points 55,075
Experience Level 12

4,925 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 730
Lessons
Completed
Best Reply Awards 7
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.

30 Dec
3 months ago

bencarter78 left a reply on Featured Posts, Companies? Idea For Store?

If I understand you correctly, I would probably do this...

Schema::create('company_features', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('company_id')->references('id')->on('companies');
    $table->timestamps();
    $table->softDeletes();
});

Using this structure, you could use the created_at and deleted_at timestamps as an alternative to 'is_featured', 'featured_from' and 'featured_to'.

By creating records to this table you will be able to record the history as well

13 Dec
4 months ago

bencarter78 left a reply on Test Dependencies

Well I would probably approach it more like this.

First, use a Factory to create the product, and by adding

// ProductFactory.php
$factory->define(Product::class, function (Faker $faker) {
    return [
        'name' => $faker->word,
    ];
});

$factory->state(Product::class, 'archived', function () {
    return [
        'deleted_at' => Carbon::now()
    ];
});

And then in my test something like

class ProductControllerTest extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function it_archives_a_product()
    {
        $product = factory()->create(Product::class);

        $response = $this->actingAsSuperAdmin()->post('/pages/admin/management/products/' . $product->id . '/archive');
        
        $response->assertStatus(200);
        $response->assertSeeText('Product sof-deleted successfully');
        $this->assertTrue($product->fresh()->trashed());
    }

    /** @test */
    public function it_deletes_a_product()
    {
        $product = factory()->states('archived')->create(Product::class);

        $response = $this->actingAsSuperAdmin()->delete('/pages/admin/management/products/' . $product->id);
        
        $response->assertStatus(200);
        $response->assertSeeText('Product deleted successfully');
        $this->assertCount(0, Product::count());
    }
}

bencarter78 left a reply on Test Dependencies

Can we see your test code?

bencarter78 left a reply on Test Dependencies

Hi, is there any reason why you are using this approach and not writing 2 independent tests?

16 Nov
5 months ago

bencarter78 left a reply on Uploading File Return Response Code 413 - Payload Too Large

Such a silly mistake, I was using the php cli .ini file to make the changes which wasn't the correct file to edit.

Thanks for the help everyone!

bencarter78 left a reply on Uploading File Return Response Code 413 - Payload Too Large

@MUNAZZIL - No change, still getting the error, memory_limit is set to -1

bencarter78 started a new conversation Uploading File Return Response Code 413 - Payload Too Large

Hello

I'm trying to debug why my server is responding with an error code when trying to upload a file to it.

I have set my php.ini file to...

post_max_size = 100M
upload_max_filesize = 64M

My /etc/nginx/nginx.conf file has the following

client_max_body_size 64M;

I have restarted nginx but still get the error.

Any ideas on how to debug this or any likely causes?

Thanks

10 Jul
9 months ago

bencarter78 started a new conversation Running Passport:install Throws ErrorException

Hello

I have just created a new L5.6 app and pulled in laravel/passport. I have then ran the migrations. However when I come to run php artisan passport:install I am getting the following error.

 ErrorException  : openssl_pkey_new(): private key length is too short; it needs to be at least 384 bits, not 0

  at /Users/bencarter/Code/Sites/test/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php:560
    556|             $config = array();
    557|             if (isset($this->configFile)) {
    558|                 $config['config'] = $this->configFile;
    559|             }
  > 560|             $rsa = openssl_pkey_new(array('private_key_bits' => $bits) + $config);
    561|             openssl_pkey_export($rsa, $privatekey, null, $config);
    562|             $publickey = openssl_pkey_get_details($rsa);
    563|             $publickey = $publickey['key'];
    564|

  Exception trace:

  1   openssl_pkey_new(["4096", "/Users/bencarter/Code/Sites/test/vendor/phpseclib/phpseclib/phpseclib/Crypt/../openssl.cnf"])
      /Users/bencarter/Code/Sites/test/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php:560

  2   phpseclib\Crypt\RSA::createKey("4096")
      /Users/bencarter/Code/Sites/test/vendor/laravel/passport/src/Console/KeysCommand.php:35

Has anyone run into this issue before? Any solutions?

Thanks

10 Jun
10 months ago

bencarter78 left a reply on How Do I Use Roles And Permissions In Controllers?

You would want to do something like this I think...

// AuthServiceProvider
public function boot()
{
    ...

    Gate::define('update-post', function ($user, $post) {
        return $user->hasRole('Admin');
    });
}

// Then in your controller...
if (Gate::allows('update-post', $post)) {
    // The current user can update the post...
}

This was basically taken from the docs here https://laravel.com/docs/5.6/authorization

05 Jun
10 months ago

bencarter78 started a new conversation Setting Up A Backend And Separate Single Page Application (SPA) Site

Hello

I am currently trying to set up the following on a Forge server.

I have created 2 sites called api.mysite.com and spa.mysite.com, I have created 2 DNS records to point my subdomains to my IP address but now I need to make requests from spa.mysite.com to the api. How do I set this up?

I have done it before but I can't remember! This is in part to document this for future use!

30 May
10 months ago

bencarter78 left a reply on A Better Way For Attaching And Detaching Pivot Items

A slightly different way to go...

public function update(Article $article, ArticleRequest $request)
{
    try {
        $article->update([
            'name' => $request->get('name'),
            'text' => $request->get('text'),
        ]);

        $article->tags()->sync(collect($request->get('tags'))->map(function($tag) {
            return Tag::firstOrCreate(['name' => $tag])->id;
        }));

        flash(trans('messages.success'), 'success');
    } catch (\Exception $e) {
        flash(trans('messages.exception'), 'danger');
    }

    return redirect(route('back.articles.index'));
}
18 May
11 months ago

bencarter78 started a new conversation How To Search Concatenated Fields With MySQL In Production And Sqlite When Testing

Hello

I have a real hacky way of trying to get my tests to pass when I'm searching a concatenated field. For example, I store my users as first_name, last_name so when I come to search I would do something like this.

ExampleModel::where(DB::raw("concat(first_name, ' ', surname)"), 'LIKE', "%$term%")->get()

However, you get an error when testing (when you use sqlite) because it doesn't have the concat function. For this you would use something like this.

ExampleModel::where(DB::raw("first_name || ' ' || surname) , 'LIKE', "%$term%")->get()

Without having a check to see if your environment is testing, how would you go about searching for this that would work on both databases?

30 Mar
1 year ago

bencarter78 left a reply on How To Target A Specific Item In V-for

Something like this should work..

<template>
  <article v-for="(item, index) in items">
    <div class="media-content">
      <div class="content">
        <p>{{item.name}}</p>
        <div class="field" v-if="selectedItem == index">
          <div class="control">
            <textarea class="textarea" v-model="item"></textarea>
          </div>
        </div>
      </div>
    </div>
    <div class="media-right">
      <a @click="editReply(item, index)"><span class="icon"><i class="fa fa-pencil"></i></span></a>
    </div>
  </article>
</template>

<script>
export default {

  data() {
    return {
      items: [],
      item:'',
      selectedItem: false,
    }
  },

  methods: {

    fetchAllitems() {
      axios.get(`/items`)
        .then(response => this.items = response.data)
        .catch(error => console.log(error.response.data))
    },

    editReply(item, index) {
      this.selectedItem = index;
      this.item = item.name;
    }
  },

  created() {
    this.fetchAllItems();
  },

  }
</script>

bencarter78 left a reply on How To Target A Specific Item In V-for

You're getting that because within the for loop you are referencing isEditingItem which is a data attribute of the component. You need to specifically identify if you are editing that item. Your click handler references editItem(item), however that method doesn't appear in your code. Should it be referencing the editReply method?

bencarter78 left a reply on Laravel Api Notification

What about using Twilio? They have some great documentation (https://www.twilio.com/) and an sdk (https://github.com/twilio/twilio-php)

18 Dec
1 year ago

bencarter78 left a reply on PHPStorm - Running PHPUnit Test From 'Run Context Configuration' Gives Class 'Tests\TestCase' Not Found Error

My bad, there was something weird with that particular test file. All other tests were working but for some reason that wasn't. Deleted the file, started again and it seems to be working.

I hate not knowing!!

bencarter78 started a new conversation PHPStorm - Running PHPUnit Test From 'Run Context Configuration' Gives Class 'Tests\TestCase' Not Found Error

Hello

I have one of those issues where it was working last week, but for some reason today it's not working.

I had a workflow with PHPStorm whereby I could place my cursor in a test method and 'Run context configuration' and it would test that method. Today (after a reboot) it shows me the error Class 'Tests\TestCase' not found.

I've managed to set up a specific configuration for a test method but of course, don't want to set one up for everyone! I had it before where it just seemed to work but it's been so long since I set it up that I've forgotten what I did to get it working where this would always just work.

Can anyone help?

11 Dec
1 year ago

bencarter78 left a reply on Getting The Value Of A String Being Cast As A Binary String

iconv("utf-8", "utf-8//ignore", b"My description string") seemed to do the trick!

bencarter78 started a new conversation Getting The Value Of A String Being Cast As A Binary String

I am querying an Advantage Database Server and one of the results returns the following...

["description" => b"My description string"]

I'm using Lumen and when I return this in a json response I got the following error.

UnexpectedValueException in Response.php line 397: The Response content must be a string or object implementing __toString(), "boolean" given.

My question is, how to convert b"My description string" into a string that I can return in the response?

The server is running PHP 5.5 (I know, I know...).

Can anyone help?

Thanks

07 Dec
1 year ago

bencarter78 left a reply on Trying To Understand Why AssertJson Fails

@cruskai Sorry I have just noticed in my controller I had left $this->response() in, that actually calls response()->json(). I'll update my original post.

bencarter78 started a new conversation Trying To Understand Why AssertJson Fails

Hello

I was hoping someone could help me understand why my test would be failing. The failure message says

Unable to find JSON: 

[{
    "sectors": [
        {
            "code": "OM326",
            "name": "Et Rerum",
            "department_id": 1,
            "updated_at": "2017-12-07 13:01:12",
            "created_at": "2017-12-07 13:01:12",
            "id": 1,
            "title": "[OM326] Et Rerum"
        }
    ]
}]

within response JSON:

[{
    "ok": true,
    "data": {
        "sectors": [
            {
                "id": 1,
                "code": "OM326",
                "name": "Et Rerum",
                "department_id": "1",
                "created_at": "2017-12-07 13:01:12",
                "updated_at": "2017-12-07 13:01:12",
                "deleted_at": null,
                "title": "[OM326] Et Rerum"
            }
        ]
    }
}].

My test for this is

$sectors = factory(Sector::class)->create();

$this->json('GET', route('api.apply.sectors.index'))->assertJson(['sectors' => [$sectors]]);

And my endpoint is

public function index()
    {
        return $this->response([
            'sectors' => Sector::all(),
        ]);
    }

I'm not understanding why it can't find the array. Can someone help?

Thanks

05 Dec
1 year ago

bencarter78 started a new conversation VS Code Xdebugging Throws DecryptException: The Payload Is Invalid.

Hello

I've just started playing with visual studio code and am trying to set up debugging. I have successfully set it up and debugged a simple php script, however, when I try to debug my L5.4 app I get the following exception being thrown...

Illuminate\Contracts\Encryption\DecryptException: The payload is invalid.

Any ideas why it might be getting thrown? Am I missing something in the set up?

Thanks

23 Nov
1 year ago

bencarter78 left a reply on Testing Api - DELETE Request Gives 404 Response

Thanks @bobbybouwmann, you highlighted the issue to me. In my destroy controller method I was typehinting the Request object. By removing it, I had my test passing.

22 Nov
1 year ago

bencarter78 started a new conversation Testing Api - DELETE Request Gives 404 Response

Hi

I am trying to test one of my api endpoints which is working in the browser but I can't get the test to pass as it returns a 404 from the request.

// api.php
Route::group(['prefix' => 'v1'], function () {
    Route::group(['prefix' => 'blink'], function () {
        Route::delete('vacancies/{vacancy}', 'Api\V1\Blink\[email protected]')->name('api.blink.vacancies.destroy');
    });
});

// php artisan route:list
| DELETE | api/v1/blink/vacancies/{vacancy} | api.blink.vacancies.destroy | App\Http\Controllers\Api\V1\Blink\[email protected] | api |

// Test
public function test_it_deletes_a_given_vacancy()
{
    $vacancy = factory(Vacancy::class)->create();
    $this->json('DELETE', '/api/v1/blink/vacancies/' . $vacancy->id)->assertStatus(200);
    $this->assertNotNull($vacancy->deleted_at);
}

When I was building out the frontend, I used the following request

this.$http
    .delete('/api/v1/blink/vacancies/' + this.vacancyId, {user_id: this.userId})
    .then()...
    .catch()....

This was also giving me a 404 but when changing it to the below, it worked

this.$http({
    method: 'delete',
    url: '/api/v1/blink/vacancies/' + this.vacancyId,
    data: {user_id: this.userId}
})

Can anyone help me to get my test passing?

Thanks

11 Sep
1 year ago

bencarter78 started a new conversation Binary String Cast Appears In Response Causes 'Response Content Must Be A String Or Object Implementing __toString(), "boolean" Given' Error

Hello

I'm trying to debug a The Response content must be a string or object implementing __toString(), "boolean" given. error I'm getting.

My app makes a call to a lumen api returns over 600 results an Advantage Database Server (over which I have no control).

I've narrowed it down to a particular record that is creating the error, for some reason, it looks like it's cast to a binary string.

    {
      "plan": "306A3CO003"
      "descrip": b"OM306 APP3 STANDARD                "
      "ilr_fwork": null
      "ilr_fworkpath": "0  "
      "main_aim": "ELECTRIC"
      "main_aim_desc": b"Installation Electrician/Maintenance Electrician                                                   
 "
    }

Can anyone advise me as to what might cause the 'b' (binary string) to appear on just this record?

06 Sep
1 year ago

bencarter78 started a new conversation CURL Error 60: SSL Certificate Unable To Get Local Issuer Certificate

  • Ubuntu: 15.04
  • Laravel: 5.4.32
  • GuzzleHttp\Guzzle: ~6.0

Hi there

I have the following error when I am trying to reset a password using Laravel's built in authentication. When I enter my email and hit reset I get...

GuzzleHttp\Exceptions\RequestException cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

I have googled this error and it from everything I have read I have tried the following, all of which have not worked...

  • Ran phpinfo() to find the correct php.ini
  • Updated the curl.cainfo php.ini settings to "/etc/ssl/certs/cacert.pem"
  • Updated the curl.cainfo php.ini settings to "/etc/ssl/certs/ca-certificated.crt"
  • Updated the openssl.cafile php.ini settings to "/etc/ssl/certs/cacert.pem"
  • Updated the openssl.cafile php.ini settings to "/etc/ssl/certs/ca-certificated.crt"

After each I have restarted apache, however, nothing has worked.

I have also ran var_dump(openssl_get_cert_locations()); which gave me the following...

[
    "default_cert_file" => "/usr/lib/ssl/cert.pem", 
    "default_cert_file_env" => "SSL_CERT_FILE",
    "default_cert_dir" => "/usr/lib/ssl/certs",
    "default_cert_dir_env" => s"SSL_CERT_DIR",
    "default_private_dir" => "/usr/lib/ssl/private",
    "default_default_cert_area" => "/usr/lib/ssl",
    "ini_cafile" => "/etc/ssl/certs/ca-certificates.crt",
    "ini_capath" => "/etc/ssl/certs" ,
]

Can anyone give me some ideas to try? What am I missing?

Thanks

24 Aug
1 year ago

bencarter78 started a new conversation Mac Users: How Do You Test Your Site On Different Versions Of IE?

Hello

I'm trying to test my application which needs to support > IE10 and I'm having a real hard time getting a productive workflow. Currently, I've got Browserstack, but it's pretty horrible (slow, crashes a lot etc).

Just wondering what people are using out there in Laravel land?

08 Aug
1 year ago

bencarter78 left a reply on Posting To Unauthenticated Api Endpoint Redirects To Login

Thanks everyone. The issue was that it was not realising it needed to respond to json. The problem was in the test. Instead of...

/** @test */
public function it_returns_the_errors_when_required_fields_are_missing()
{
    $this->post('/api/v1/blink/enquiries', [])->assertStatus(422);
}

...it should have been...

/** @test */
public function it_returns_the_errors_when_required_fields_are_missing()
{
    $this->json('POST', '/api/v1/blink/enquiries', [])->assertStatus(422);
}
07 Aug
1 year ago

bencarter78 left a reply on Posting To Unauthenticated Api Endpoint Redirects To Login

The only middleware applied to the route is api

bencarter78 started a new conversation Posting To Unauthenticated Api Endpoint Redirects To Login

Hi there

I am trying to post data from a form to an endpoint I have. My test is giving me a 302 response when I am looking for a 422 (invalid data). I opened Postman and had a look and it shows the login page when posting to the endpoint.

I was expecting a 422 response code with the errors (as per the docs)...

"If the request was an AJAX request, a HTTP response with a 422 status code will be returned to the user including a JSON representation of the validation errors."

There is no auth middleware on the endpoint so I don't understand why it would be redirecting me. If I make a GET request to a method in the same controller it returns the data as I would expect.

/** @test */
public function it_returns_the_errors_when_required_fields_are_missing()
{
    $this->post('/api/v1/blink/enquiries', [])->assertStatus(422);
}
// Controller
public function store(ApiEnquiryRequest $request)
{
    // Storing...

    return response()->json(['ok' => true], 200);
}
// FormRequest

public function rules()
{
    return [
        'search' => 'required',
        'note' => 'required',
    ];
}

What am I doing wrong?

03 Aug
1 year ago

bencarter78 started a new conversation IE 11 - Code Failing When Using Syntax...for (let Item Of Items)

I'm just looking for someone to help me try to understand why the following code does not work in IE 11 but works in other browsers.

I have a L5.4 app using Vue which when my page loads it makes an api call to fetch users, this is then displayed in a vue data table (https://github.com/matfish2/vue-tables-2). I can see that it fetches the data, the problem lies in how I extract what I want to display.

When I compile my js down (using npm run dev/watch/production) the following works in Chrome, but not IE.

// Vue component method
getMemberships (items, key) {
    for (let item of this.sort(items, key)) {
        html.push(item[key])
    }
    return html.join(", ");
},

However, this works on both browsers.

// Vue component method
getMemberships (items, key) {
    let html = []
    this.sort(items, key).forEach(item => {
        html.push(item[key])
    })
    return html.join(", ");
},

Does anyone know why?

23 Jul
1 year ago

bencarter78 started a new conversation Middleware Being Ignored On Api Controller

Hi there

I am building an api server for an app and I am trying to add a middleware to one of my controllers but it seems like it is being ignored.

I have declared it in the $routeMiddleware property...

protected $routeMiddleware = [
        ...
    'auth.member' => \App\Http\Middleware\AuthorizeMember::class,
    ];

I have then used it in the constructor on my controller...

class MyController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth.member');
    }

If I run php artisan route:list I can see that the middleware is being applied to the correct route, however, I'm just trying to log/dd something to see if it's being executed but it's not logging anything.

class AuthorizeMember
{
    public function handle($request, Closure $next)
    {
        Log::info('AuthorizeMember');

        dd( $request );
    }
}

What am I doing wrong?

12 Jun
1 year ago

bencarter78 started a new conversation Seeking Advice For Implementing API Authentication

Hello

I have a 'regular' site where users log in via email/password. I need to implement an API that implements authentication. I know there is Laravel Passport, but that seems for when a site is using oauth.

Does anyone have any advice on the best way to achieve this or links to good articles?

Thanks

05 Jun
1 year ago

bencarter78 started a new conversation Submitted Form Input Arrays Are Duplicating

Hello

I have a very strange thing that seems to be happening.

I have a form with an input array (for the purposes of this there is only one though) which when it gets submitted and I dd the result I can see the value gets duplicated.

Here's my code...

// Controller
class FormController extends Controller
{
    public function index(Request $request)
    {
        if ($request->has('grade_id')) {
            dd($request->all());
        }

        return view('form');
    }
}

// View
<form class="form-horizontal" method="get" action="{!! route('form-test') !!}">
    <input name="grade_id[]" value="1" type="checkbox" id="grade_id" class="grade_id">Outstanding
    <button type="submit" class="btn btn-secondary btn-block">Search</button>
</form>

// Result
array:1 
  "grade_id" => array:2
    0 => "1"
    1 => "1"
  ]
]

What's happening?

If you want to check it out for yourself I have created a repo for it. https://github.com/bencarter78/form-test

Weirdly someone from the larachat slack room tried out the repo and it worked fine for them but when I do it I get it duplicated. Why might we be getting 2 different results for something like this?

02 Jun
1 year ago

bencarter78 left a reply on HTTP Test Failing On ActingAs

Well that was a frustrating couple of hours! Eventually realised the problem was that the route was inside a route group which had an extra middleware associated with it.

bencarter78 started a new conversation HTTP Test Failing On ActingAs

Hi there

I'm trying to write a simple HTTP test for an authenticated user but I'm getting the following error.

Failed asserting that '<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="1;url=http://myurl.dev" />

        <title>Redirecting to http://myurl.dev</title>
    </head>
    <body>
        Redirecting to <a href="http://localhost:3000">http://myurl.dev</a>.
    </body>
</html>' contains "Filter Criteria".

So it seems like it's attempting to do some kind of redirect (which I assume is where it's trying to authenticate?).

My test is just this...

$user = factory(User::class)->states('admin')->create();
$this->actingAs($user)
    ->get('/judi/analysis/criteria')
        ->assertSee('Filter Criteria');

Can anyone point me in the right direction?

28 Apr
1 year ago

bencarter78 left a reply on Fontawesome With Webpack And Laravel 5.4, Wrong Path To Fonts

Actually I found that it wouldn't compile with the file extension. This works for me...

// resources/assets/sass/app.scss
$fa-font-path: "../../../node_modules/font-awesome/fonts" !default;
@import "node_modules/font-awesome/css/font-awesome";
23 Feb
2 years ago

bencarter78 left a reply on PutFile Method Stores Mp3 Files As .bin In Laravel

I was finding the same issue but for a .docx file. I noticed that the $request->file('filename')->extension() method was incorrectly defining the filetype.

It actually says this in the docs

File Paths & Extensions ...This extension may be different from the extension that was supplied by the client

I got around this with the following...

$request->file('filename')->storeAs(
    $directory,
    $request->file('filename')->getClientOriginalName() . '.' . $request->file('filename')->getClientOriginalExtension()
);
21 Feb
2 years ago

bencarter78 left a reply on Checking Multiple Checkboxes With Laravel Dusk

@Defrag That almost worked I just needed to tweak it

$browser->check("input[name='department_id[]']");

This will select the first one however it got me thinking how to select say the first third and fifth ones.

I think the following should work

// View
@foreach ($departments as $department)
    <tr>
        <td>
            <input type="checkbox" name="department_id[{!! $department->id !}}]" value="{!! $department->id !}}" />
        </td>
        <td>{!! $department->department !!}</td>
    </tr>
@endforeach 

// Test

// You could loop over or be explicit about which ones you want to select 
$browser->check("input[name='department_id[" . $department->id . "]']")

bencarter78 started a new conversation Checking Multiple Checkboxes With Laravel Dusk

Hi there

Can anyone tell me how you can check multiple checkboxes with Dusk? I have the following code...

@foreach ($departments as $department)
    <tr>
        <td>
            <input type="checkbox" name="department_id[]" value="{!! $department->id !}}" />
        </td>
        <td>{!! $department->department !!}</td>
    </tr>
@endforeach 

In my test I am trying to select one of those checkboxes...

$browser->visit('my-page')->check("department_id[]");

I get the error invalid selector: An invalid or illegal selector was specified

Can anyone help?

Thanks

15 Feb
2 years ago

bencarter78 left a reply on Did I Lose My Search Privilege?

I can't see my account section in the header any more

12 Feb
2 years ago

bencarter78 left a reply on Laravel Dusk Test Hanging On Login

@gabiyo In my case, I was trying to access a part of my application as a normal user when it needed to be a super user with admin privileges

08 Feb
2 years ago

bencarter78 left a reply on Sorting The Table By Status

It depends on how you are storing status. For example, if it is a string then you could do something like...

User::orderBy('status')->get();

bencarter78 left a reply on How To Register A User Programmatically?

Can't you do something like...

User::create([
    'name' => 'Joe User',
    'email' => '[email protected]',
    'password' => 'j0eybaby',
    'password_confirmation' => 'j0eybaby',
    'terms' => true,
    'busy' => true,
    'successful' => false
]);



event(new UserRegistered($user));

Maybe put this in a console command depending on your use case?

bencarter78 left a reply on Route Model Binding In Group With Domain Definition

I don't think you can pass in the model to the function in the second parameter of Route::group as it passes in a router instance to the closure. (https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php#L323)

You would have to pass it to the HTTP verb (e.g. Route::get/post etc)

Route::get('api/users/{user}', function (App\Models\App $app) {
    return $app;
});

From the docs https://laravel.com/docs/5.3/routing#route-model-binding

07 Feb
2 years ago

bencarter78 left a reply on Dusk Problem: DatabaseTransactions

As far as I know, DatabaseTransactions uses a different process so we can't use it.

However, I highly recommend using an SQLite db (not an in memory one though, can't use that either) for testing with dusk.

I was using MySQL for my 10 tests which was taking 2m 30secs, switched to SQLite and got it down to 30 secs. BIG win.

In my database.config...

'dusk' => [
        'driver' => 'sqlite',
        'database' => database_path('dusk.sqlite'),
    'prefix' => '',
]

@mstnorris sent me a nice article to get started with https://medium.com/@splatEric/working-with-laravel-dusk-54d67cc0241b#.b4va8ibx8

01 Feb
2 years ago

bencarter78 left a reply on Dusk Problem: DatabaseTransactions

I'm having the same error here. Using DatabaseMigrations works fine, but when I use DatabaseTransactions I get

Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given
30 Jan
2 years ago

bencarter78 left a reply on Laravel Dusk Test Hanging On Login

I think this was actually caused by the user not having permission to view the page (my bad), however, it was just getting stuck on the url, and not returning to one of my application pages. With the flash error message.

If anyone else finds this thread check the permission of the user, it might be the problem.