testy

testy

Member Since 4 Years Ago

Experience Points
3,155
Total
Experience

1,845 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
7
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 1
3,155 XP
16 Jan
1 year ago

testy started a new conversation "whereHas" And "with" In Eloquent

Hey all,

i have this eloquent model scope:

public function scopeActiveAssignments($query, $customerId)
{
      return $query->whereHas('assignments', function($q) use ($customerId) {
          return $q->where('status', 1)->where('customer_id', $customerId);
        })
        ->with(['assignments' => function($q) use ($customerId) {
          return $q->where('status', 1)->where('customer_id', $customerId);
        }]);
}

It checks if it has active assignments, and return this. But i need to make the check twice. If i try to make the with call without callback, it returns me all assignments and ignore the whereHas block :(

24 Oct
1 year ago

testy left a reply on Mockery With Laravel Don't Mocks A Method

But i change the instance in the container with

$this->app->instance($class, $mock);

in my mock() function.

24 Feb
2 years ago

testy started a new conversation Scout - How To Search In Relations And Counts?

I have the following Eloquent scope:

return $query->where('title', 'like', '%' . $title . '%')->orWhereHas('alternatives', function($query) use ($title) {
     return $query->where('title', 'like', '%' . $title . '%');
});

^ this scope will be called in controller like this:

return $this->item->findByTitle($title)->with('latestEpisode')->withCount('episodes')->get();

Is there a way to make this happens in Laravel Scout? I have the follwing:

return $this->item->search($title)->get()->load('latestEpisode');

^ few problems here: There isn't a method for withCount for Scout. The second problem is, how do i query the alternatives relation as above in my normal Eloquent scope?

01 Feb
2 years ago

testy left a reply on Problem With Unit Test Input::file

Ok...this answer was the solution...lol

https://laracasts.com/index.php/discuss/channels/tips/how-do-you-unit-test-file-uploads/replies/300760

Make sure you are using Illuminate\Http\UploadedFile to mock your file and not Symfony\Component\HttpFoundation\File\UploadedFile.

testy started a new conversation Problem With Unit Test Input::file

This is my controller:

public function bla() {
  $file = Input::file('bla') ?: 'NO FILE';

   print_r($file);

   // ... more
}

And this is my test:

$filename = 'bla-file.txt';
$path = __DIR__ . '/fixtures/' . $filename;

$file = new UploadedFile($path, $filename);

$this->actingAs($this->user)->json('POST', 'api/bla', ['bla' => $file]);

PHPUnit prints always NO FILE from my controller in my console. I checked the laravel framework for json method. There is an method extractFilesFromDataArray which returns the correct key, because the bla key is an instanceof SymfonyUploadedFile.

But the Input::file('bla') is not set :(

19 Dec
2 years ago

testy started a new conversation Many Checks With Loop If Data In Database Is Available

Hey guys. I need a tip:

I have the following code:

$allTitles = $service->getAllTitles();

foreach($alternativeTitles as $title) {
  $availableTitle = ServiceTitle::where('title', $title->title)->where('service_id', $item['service_id'])->first();

  if( ! $availableTitle) {
    $alternativeTitle = new ServiceTitle();
    $alternativeTitle->service_id = $item['service_id'];
    $alternativeTitle->title = $title->title;
    $alternativeTitle->save();
   }
 }

Let's assume $allTitles are a collection of 5000 titles. In the foreach loop i check against the database, if the title is already available. After that, i store the new title. So, the available check only runs a few minutes :( Is there an better way?

16 Dec
2 years ago

testy started a new conversation How To Mock An DI In A Controller Methods

Hey all. I'm very new to testing and try to test my app.

Here is my method in HomeController

use GuzzleHttp\Client;

public function getNewVersions(Client $client) {
  $response = json_decode($client->get('URL')->getBody());
  $last = $response[0]->name;
  return version_compare($this->version, $last, '<') ? 'a new version' : 'no new version'
}

My test look like this:

public function testGetNewVersions() {
  config(['app.version' => '2.0.1']);

  $mock = new MockHandler([
    new Response(200, [], file_get_contents('FILE WITH TEST DATA')),
  ]);

  // How do i pass this mocked $client into my method in controller?
  $client = new Client(['handler' => HandlerStack::create($mock)]);

  // Normaly i would test my controller method with a normal route. Or do i need to make what different?
  $response = $this->actingAs($this->user)->json('GET', 'api/check-update');
}

I read a bit about Mocking and Testing Guzzle itself...but i can't understand how to test it with my controller.

25 Nov
2 years ago

testy left a reply on Eloquent How To Group Data By An Row

Oohh thanks, i tried it with groupBy('type')->get(), but it doesn't worked. But get()->groupBy('type') works!

testy started a new conversation Eloquent How To Group Data By An Row

I have the following table:

id  type  title
--  ------  -----
1    1         title-1
2   2        title-2
3   2        title-3
4   2        title-4
5   1         title-5

and i need the following result grouped by the type row:

[o] => array with:
  [1] => [array full of items with type of 1]  
  [2] => [array full of items with type of 2]

Is this possible withing eloquent, or i need to sort manuelly in php?

18 Oct
2 years ago

testy started a new conversation Call To Undefined Method App\Services\Storage::disk()

I try to instantiate the Storage/Filesystem with DI.

use Illuminate\Filesystem\Filesystem;

class Bla {
   public __construct(Filesystem $storage) {...}
}

But if i run $this->storage->disk(...) it says me Call to undefined method App\Services\Storage::disk(). All other methods works...i tried it with

use Illuminate\Support\Facades\Storage;
or
 use Illuminate\Contracts\Filesystem\Filesystem;

// Edit: i found my error...can anyone delete this topic^^

14 Oct
2 years ago

testy started a new conversation Collections Get Only Specific Key Value

Here is my collection (simplified as array):

[0] => Array
                (
                    [tmdb_id] => 343611
                    [title] => Jack Reacher: Never Go Back
                    [poster] => /IfB9hy4JH1eH6HEfIgIGORXi5h.jpg
                    [released] => 1476866372
                )

            [1] => Array
                (
                    [tmdb_id] => 284052
                    [title] => Doctor Strange
                    [poster] => /xfWac8MTYDxujaxgPVcRD9yZaul.jpg
                    [released] => 1477384772
                )

            [2] => Array
                (
                    [tmdb_id] => 14564
                    [title] => Rings
                    [poster] => /ueu1Mo2XRZ2C2aBisP30e1d5SmA.jpg
                    [released] => 1477557572
                )

I need an new array with only title from each array. How? :(

This works

$allTitle = $items->map(function($item) {
        return $item['title'];
      });

but is there an better way?

11 Oct
2 years ago

testy left a reply on Artisan::call In Controller Does Not Work

Yes

  use Illuminate\Support\Facades\Artisan;

testy started a new conversation Artisan::call In Controller Does Not Work

Hey all!

I run the following command in my controller:

public function syncScout()
    {
      Artisan::call('system:sync');
    }

but it doesn't work. If i change it to call env or something else, it doens't return anything. If i var_dump my call, it says int(0). I use Laravel 5.3. Artisan facade is imported.

06 Sep
3 years ago
05 Sep
3 years ago

testy started a new conversation Question About Storage:link And Public/storage

So, how does this work? I i run this artisan command, what it does in the background? Does this work with xampp on windows?

17 Aug
3 years ago

testy left a reply on Homestead - Mysql Different Port For CLI And Web

Oh wow, thank you...this makes sense!

testy started a new conversation Homestead - Mysql Different Port For CLI And Web

Hey all!

I have following problem: I use the current Homestead on my Mac. The DB_PORT for mysql is set to 3306. This port works with my website, it can connect to the databse.

But, if i need to run an artisan command, like migrate, it say me SQLSTATE[HY000] [2002] Connection refused. But, if i change the Port to 33060, it works on the CLI, but not in my web app more :( In the documentations of homestead is it written that i need the 33060 Port to connect my database with an client.

testy started a new conversation Command Call "scout:import" With Argument

Hey all!

I need to call php artisan scout:import "App\Movies" in my custom command:

public function handle()
{
    $this->call('scout:import "App\Movies"');
}

But this show me

Command "scout:import "App\Movies"" is not defined.
Did you mean this?
    scout:import

I read that i need to provide arguments in an second parameter as array. But how do i write the App\Movies as argument in array?

This $this->call('scout:import', ["App\\Movies"]) give me Not enough arguments (missing: "model"). Anyone an idea?

// Edit: Whoooooops.... ["model" => "App\\Movies"] works <.<

testy left a reply on L5.3 With Scout Fatal Error

Have the same problem :/ Maybe make an github issue?

16 Aug
3 years ago

testy started a new conversation CSRF In SPA Expired

Hey all!

I have a question. I use laravel with vue. In vue, i have the following code to set my CSRF token:

Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('content');

But, if i have my site open for, say, 1 or 2 hours without an request or something, the CSRF expired and i can't do anything without to reload my website. Is there an trick for that? Like an ajax request for every 15minutes or so? Does this help?

08 Aug
3 years ago

testy left a reply on Need Advice How To Structure Code, That Is Used In 2 Controller

@MikeHopley thank you very much! :) is there an laracasts video for something like this?

testy started a new conversation Need Advice How To Structure Code, That Is Used In 2 Controller

Hey all!

I have 2 controller: MoviesController and TMDBController. In MoviesController i create, update and delete my movies list. In the TMDBController i use the TMDB API for searching new movies and display them (return json for my view).

Here is my TMDBController (a bit simplified):

private $client;
    private $key;

    public function __construct()
    {
      $this->key = env('TMDB_KEY');
      $this->client = new Client(['base_uri' => 'http://api.themoviedb.org/']);
    }

    public function search()
    {
      $title = Input::get('q');
      $items = [];

      $response = $this->client->get('/3/search/movie', ['query' => ['api_key' => $this->key, 'query' => $title]]);
      $response = json_decode($response->getBody());

      foreach($response->results as $result) {
        $items[] = [
          // .. set key/values
        ];
      }

      return $items;
    }

And in my MoviesController i need to call the tmdb api again (for detailed search) after i added an movie to my database.

private function parseDetails($tmdb_id)
    {
      $key = env('TMDB_KEY');
      $client = new Client(['base_uri' => 'http://api.themoviedb.org/']);

      $response = $client->get('/3/movie/' . $tmdb_id, ['query' => ['api_key' => $key]]);
      $titles = collect(json_decode($response->getBody())->titles);

      // ... bla bla
    }

So, i call the same api in my MoviesController and TMDBController, init api key etc...is there an other and better way to restructure my api call? To use them in both controllers once?

29 Mar
3 years ago

testy started a new conversation Overwhelmed By Tests

I try to make tests for my webapp. But i don't know how and where to start.

It's a laravel app, but with vue as frontend. How do i test this all? Need i test the backend (laravel) and the frontend the same way? Which test tools are for frontend? What is the difference between Karma, Nightwatch, Jasmine or Selemnium? :/

10 Mar
3 years ago

testy started a new conversation Vue - Is There An Way In V-for To OrderBy $index

I need to to order an list with v-for by $index. So that the last entry on my array comes first.

09 Mar
3 years ago

testy started a new conversation Vue.js Listen For Key Events On Div

Is there an way to listen for space or other key OUTSIDE from input fields?

Something like

<div @keyup.space="method()">

</div>

29 Feb
3 years ago

testy started a new conversation Laravel Array Collections Question

Hello,

i have this collection array:

// Collection Items
0 => [
    'first' => 'first item',
    'second' => [
        'key1' => 'value 1',
        'key2' => 'value 2',
        'key3' => 'value 3',
        'key4' => 'value 4',
        'key5' => 'value 5',
    ]
],
1 => [
 // same...
],
// more

I need a new array with only few keys (and value) from all second array in my collection items (e.g. key 2 and key 4)

I tried it with $plucked = $items->pluck(['second.key1', 'second.key2']) but it does not work.

testy started a new conversation Laravel Chache Problem Guzzle Response

I try to add my guzzle response to laravel cache:

$value = Cache::remember('api', 1, function() {
      $url = "xxx";

      $client = new GuzzleHttp\Client();
      $res = $client->request('get', $url);

      return $res->getBody();
    });

    return $value;

The first response (without cache) works, but then (if result is cached), it returns nothing :(

01 Feb
3 years ago

testy started a new conversation Vue-Resource Post-Request No Data

I try a POST Request with Vue-Resource (with data):

Vue.http.post('subscribe', {email: this.email, hp: this.address}).then((val) => {
       console.log(val);
});

But if i try to print_r($_POST), there is an empty array.

If i do this with jquery:

$.ajax({
        url: 'subscribe',
        type: 'post',
        data: {
          email: 'email',
          name: 'name'
        }
      }).done(function(val) {
        console.log(val);
      })

It works fine :/

23 Nov
3 years ago

testy started a new conversation What For Test-Frameworks For Laravel 5.1?

What do you guys use for Test-Frameworks for Laravel 5.1 (other then PHPUnit)? Is Codeception good (or is the core features are includet in Laravel 5.1?)

Has anyone a good Folder Structure for Testing?

14 Oct
3 years ago

testy started a new conversation Cachebusting For "watch" Does Not Work

This is my simple gulpfile

  mix.sass('app.scss');
  mix.browserify('../../../app/app.js');
  mix.version(['assets/build/css/app.css', 'assets/build/js/app.js']);

If i run gulp, i become an new versioned file from my js and css. But if i run gulp watch, and every time i trigger a change in my css or js file, it does not rerun the version function :(

30 Jul
4 years ago

testy started a new conversation Problem With ES6-Browserify After Update To 3.0

Browserify Failed!: /filename: Unexpected token (9:8) while parsing file: filename

I updated my Elixir version to 3.0.6, and became this error. I use React with ES6 class syntax:

class Bla extends React.Component {

  state = { // <-- Row 9
    items: []
  }

// ...

But why? This is correct ES6 Syntax

20 Jul
4 years ago

testy left a reply on Swift_TransportException Expected Response Code 220

encryption is null, does not work :(

testy started a new conversation Swift_TransportException Expected Response Code 220

I have a problem on my shared host from 1and1.

PHP Version is 5.6 and Laravel 5.1. I try to send an e-mail with SENDMAIL, not smtp.

But it gives me the following error:

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 220 but got code "", with message ""

Anyone an idea?

16 Jul
4 years ago

testy started a new conversation Get X Items From A Table By An Value In Eloquent

Hai,

i have a table with many items. Each have an category (names: '1', '2', '3' or '4').

So, how can i get 5 items from each category in Eloquent? Currently i have


$items = Item::with('cat')->get();

But if i make an Item::with('cat')->take(5)->get() i became only 5 items overall.

21 Jun
4 years ago

testy started a new conversation Vue.js With Router

Has anyone an great boilerplate for vue.js with clean (html5history) routes and with laravel?

I use the npm director router, but he need server and client site routes, when i use html5history routes. Or how can i handle this with laravel? :(

28 May
4 years ago

testy started a new conversation Lumen Auth::attempt Does Not Work

Hey, i tried to make an Auth system in Lumen. I have implements the Authenticatable Contract to my User Model. The users table is set.

My env:

AUTH_DRIVER=ELOQUENT
AUTH_MODEL=USER
AUTH_TABLE=USERS

SESSION_DRIVER=file

The Auth::check() method works, but the Auth::attempts() not. I became an 500 error, without more infos :(

My User Model:

<?php

  namespace App;

  use Illuminate\Contracts\Auth\Authenticatable;
  use Illuminate\Database\Eloquent\Model;

  class User extends Model implements Authenticatable {

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
      // TODO: Implement getAuthIdentifier() method.
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
      // TODO: Implement getAuthPassword() method.
    }

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string
     */
    public function getRememberToken()
    {
      // TODO: Implement getRememberToken() method.
    }

    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string $value
     *
     * @return void
     */
    public function setRememberToken($value)
    {
      // TODO: Implement setRememberToken() method.
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
      // TODO: Implement getRememberTokenName() method.
    }}

I dont have any methods on work, is this required?

The middlewares are all active.

And this is my try:

if( ! Auth::attempt(Request::all())) { ... }

The Request::all() return an array with username and password.

23 Apr
4 years ago

testy left a reply on Statamic Vs. October

I need an simple flat file cms like kirby http://getkirby.com, but they all costs money :|

testy started a new conversation Statamic Vs. October

Hello, I have to decide because of my work for a CMS. Great as WordPress I do not need.

Most pages are easy for companies without great features.

Since I work a lot with Laravel, I noticed directly october. But somehow ... I do not know whether the customers are in a good position to cope with it.

Then there is Statamic what apparently soon to run under lumen?

Does anyone have experience with them?

15 Apr
4 years ago

testy left a reply on Lumen

Hm, i have the same error :/ Using mamp. I have tried with RewriteBase to pointing to the public folder, but not working :/

Laravel is no problem

01 Apr
4 years ago

testy started a new conversation Can Not Send Emails Fatal Error: Call To A Member Function ClearAll() On A Non-object

I switch my webspace to www.united-domains.de.

But when i will send an email, i become the follow error :/

Fatal error: Call to a member function clearAll() on a non-object in /webspace/10/89919/domain.de/server/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php on line 828

04 Feb
4 years ago

testy left a reply on TokenMismatchException In VerifyCsrfToken.php Line 46

Oh man, it was my fault, i changed the directory name of my app, and do not update my .htaccess

testy started a new conversation TokenMismatchException In VerifyCsrfToken.php Line 46

I have upgraded my 2 weeks old L5 code with the newest changes.

But, i became this error everytime:

php TokenMismatchException in VerifyCsrfToken.php line 46php

I make a ajax request. The _token input is correct...have i missed anything?

testy started a new conversation Laravel 5 Fundamentals Are FREE!

HOLY FU*****!! Thank you jeff!!

28 Jan
4 years ago

testy started a new conversation Laravel 5 Response()->json() Is A Undefined Method

I do this in my controller:

return response('correct', 200)->json([]);

But this is the error:

Call to undefined method Illuminate\Http\Response::json()

27 Jan
4 years ago

testy left a reply on Laravel 5 Problems With Relations Pivot

thanks you soooo much <3

testy left a reply on Laravel 5 Problems With Relations Pivot

Ok, i will output a list of entrys. On the right is an icon that show if the current user has this entry as favourite. (In the favourites table). But I would also have access to all of a user's favourites ( in another view).

testy left a reply on Laravel 5 Problems With Relations Pivot

Thanks for your big help, but...

i make this:

  $entrys = Entry::with('users')->get();

  @foreach($entrys as $entry)
     Entry title: {{ $entry->title }}
     User has this entry as favourite? {{ $entry->user->favourite === $entry->id ? 'yep' : 'no' }}
  @endforeach

But this not work