rhand

rhand

Member Since 2 Years Ago

Experience Points
10,850
Total
Experience

4,150 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
88
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 3
10,850 XP
Jan
23
4 days ago
Activity icon

Replied to Xdebug N+1 71 Duplicate Queries - Lazy Eager Loading

Currently the Trait trait ProjectHelper has many methods such as


namespace App\Traits\Models;

use App\Models\Something\SomeModule;

public function orders()
    {
        return $this->hasMany(\App\Order::class);
    }

to start with. So we do start with orders() as it is.

We also have app/Order.php so I guess I could add the methods you improved under the order class there, but I think I will keep it in here for now if possible.

I was thinking about using something like ->with but your solution without () and using the collection where to create a collection sounds like a good idea. Especially since it should reduce calls without the().

I had no clue.. and I am still struggling, but learning thanks to you.

But why then would we need the controller part:

// In your controller
$myModels = MyModel::with('orders')->get();

foreach ($myModels as $myModel) {
    $myModel->lastExpiresPlan;
    $myModel->isTrial;
}

?

Activity icon

Started a new Conversation Xdebug N+1 71 Duplicate Queries - Lazy Eager Loading

Using Debugbar I see that our Projects Overview on Dashboard currently gets 71 duplicate queries and many duplicates point to: app/Traits/Models/ProjectHelper.php line 71

public function getActiveOrderAttribute()
    {
        return $this->orders()->where('status', 'paid')
                    ->where('end_at', '>=', now())
                    ->orderBy('end_at', 'DESC')
                    ->first();
    }

for each project this query

select * from `orders` 
where `orders`.`project_id` = 47 and 
`orders`.`project_id` is not null and 
`status` = 'paid' and 
`end_at` >= '2020-01-23 07:33:36' 
order by `end_at` 
desc limit 1

is loaded 11 times it seems. Meaning one base query and 10 more. There are six projects. In method above I count 5 queries (N+1 issue). There are two more methods using all orders and paid check:

public function getIsTrialAttribute()
    {
        return $this->orders()->where('status', 'paid')->count() < 1;
    }

and

public function getLastExpiresPlanAttribute()
    {
        return $this->orders()->where('status', 'paid')
                    ->where('end_at', '<', now())
                    ->orderBy('end_at', 'DESC')
                    ->first();
    }

These count as another 6 queries and that would make 11 on all orders.

I think with Lazy Eager Loading I could limit the queries and avoid N+1 issues.. Never done it though. How would I do this? Should I perhaps merge some of the methods somehow or make them work together?

Jan
22
5 days ago
Activity icon

Replied to Laravel CORS Base Domain + Subs And External Domains

Yeah and if we would get a certain number of domains each day that would have to be automated if possible. Especially since we do not want to have them wait until they have been added.

Activity icon

Started a new Conversation Laravel CORS Base Domain + Subs And External Domains

We are currently using this Laravel CORS config file and Barry's Laravel CORS package to allow subdomains and external domains to load data from our JSON API on the main domein using

return [
    /*
     |--------------------------------------------------------------------------
     | Laravel CORS
     |--------------------------------------------------------------------------
     |
     | allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
     | to accept any value.
     |
     */
    'supportsCredentials' => false,
    'allowedOrigins' => ['*'],
    'allowedHeaders' => ['X-CSRF-TOKEN', 'X-REQUESTED-WITH', 'User-Agent', 'Content-Type', 'Origin'],
    'allowedMethods' => ['GET', 'POST'],
    'exposedHeaders' => [],
    'maxAge' => 0,
];

This middleware we added to our api routes fetching page data , slugs, modules and such.

We always have unknown origins as more users are added with new subdomains or third party domain names every day. With GET and POST in use we basically allow PUT and DELETE as well. And with great power comes great responsibility

Any thoughts on securing this more , but allowing external sites and subdomains to load data of the main domain?

Jan
21
6 days ago
Activity icon

Replied to Security Scanning

What plugin was that @frenchfryninja ? What is it called?

Jan
17
1 week ago
Activity icon

Replied to Posts Overview W/ Posts Per User

Thanks a lot for this thorough feedback. I am impressed. Decided to read more on where clauses and the ones that work with JSON data like https://laravel.com/docs/5.8/queries#json-where-clauses and something like

$users = DB::table('users')
                ->where('options->language', 'en')
                ->get();

$users = DB::table('users')
                ->where('preferences->dining->meal', 'salad')
                ->get();

where where is used to dig into JSON data.

It is true that with what tech offers today and offers in the future computations / RAM / CPU will become cheaper and cheaper and better and better. And that means what may worry us know demand/$ wise will not bother us anymore soon. Even now we are not paying that much for the VPSs we use at Digital Ocean. We are staying well within parameters set.

It is also a fact that we are doing some querying for JSON data for our app already and we have not had any issues really. Just was worried that blog hierarchy and the need for where queries to display per tag, category, author, date, search query and such would be a lot more demanding. But do think now it will not be that bad. And.. we can do some tests like you said to see and compare if need be.

Thanks again @bugsysha

Jan
16
1 week ago
Activity icon

Replied to Posts Overview W/ Posts Per User

Main thing on Json I was wondering about is that if I store post_title, post_slug, post_description, post_content, post_seo, posts_category as Json in one single Json content column and use queries on this Json data in a Json column will this be slower performance wise than using standard non Json columns and one separate column per item?

Activity icon

Replied to Posts Overview W/ Posts Per User

Well, the issue was, posts data is in database b and user id and other data on database a. I want to load all posts for current_user. So for that I need to connect user_id from database a table users to database b post_id. Now, that is possible but most seem to recommend to keep the posts data / most data in one single database. I was looking on your take on this.

Second thing was that we currently store a lot of frontend input data via Axios Json in the database in a json column. I was wondering if I should do this with posts data too. Posts data will have to be queries for tags, categories, by author and such so I thought that perhaps regular MySQL table dat would be better, but I was wondering. What is your opinion on this?

Activity icon

Replied to Posts Overview W/ Posts Per User

Well, I think I am going to keep blog posts in the main database as well. As Fiderloper mentioned at https://fideloper.com/laravel-multiple-database-connections:

Be careful about attempting to build relationships with tables across databases! It is possible to do, but it can come with some caveats and depends on what database and/or database settings you have.

Also see https://stackoverflow.com/q/8561412/460885

No, you can't have foreign keys between databases ...

and https://dba.stackexchange.com/q/47387/87229

.. there are very few scenarios where having multiple databases on the same server is best practice (except through the magic of virtualization). Only your first point is genuinely pertinent. Moving a schema is hardly more difficult than moving a database. Restarting is irrelevant. And the point about RAM usage is contentious (I know systems which still exist on small amounts) and fails to address all the other resources which will experience contention

Does not mean that you cannot though. As long as the database are on the same server you can create cross database relationships. See https://laracasts.com/discuss/channels/eloquent/how-to-properly-use-2-database-relationships and https://github.com/laravel/framework/issues/24398#issuecomment-539131293

public function related_models() {
        return $this->belongsToMany('App\Model',
            'database_name.pivot_table_name',
            'fk_id',
            'fk2_id')
            ->using('App\Models\PivotModel')
            ->withPivot([
                'id',
            ]);
    }
Activity icon

Replied to Posts Overview W/ Posts Per User

I guess I can use Auth User from regular model in view and for posts the posts model that loads from the blog database. I however still need to attach posts to a specific user. What approach for that?

As for JSON vs regular data in multiple rows/columns for blog data. Still debating that. Ideas are welcome.

Activity icon

Started a new Conversation Posts Overview W/ Posts Per User

I created a new database with posts table for a test. Decided to add these to a separate database not part of the main database with dashboard data. This as I feel that blogging is a different beast.

  • Started to wonder if we should use Json for this blog posts data, but as we may need many queries for display per category, tag and do searches perhaps regular SQL is better?

  • Two, how do you make a model that shows all posts for current user? User data is in base database and I connect to blog database with:

if (!Schema::connection('mysql_blog')->hasTable('posts')) {
   Schema::connection('mysql_blog')->create('posts', function (Blueprint $table) {

with the model. I want to use \auth but that then needs to check in main database unless I can import the users and or projects somehow .. seems a waste..

Current Model in progress:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // https://stackoverflow.com/questions/25952348/laravel-run-migrations-on-another-database
        // user_id and company_id as foreign keys needed here as well and currently 
        // those
        // are only in the main database
        // perhaps we need just a table blogs with all blogs loading the items below. 
        // We have
        // all the other data in the main database already
        // also, we could perhaps use json for most below and limit to id, blog_id
        // and json for all the
        // rest but it depends on the (search) queries you use and in blogs you 
        // often do and combine data

        if (!Schema::connection('mysql_blog')->hasTable('posts')) {
            Schema::connection('mysql_blog')->create('posts', 
                function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('title');
                $table->string('description');
                $table->string('content');
                $table->integer('view')->default(0);
                $table->integer('like')->default(0);
                $table->unsignedBigInteger('id_category');
                $table->foreign('id_category')->references('id')->on('category');
                $table->timestamps();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}
Jan
12
2 weeks ago
Activity icon

Replied to Registration Allows Immediate Access Despite Email Verification

Just started looking into adding verified just now. And grouping it this way is even better. Thanks @nakov

Activity icon

Started a new Conversation Registration Allows Immediate Access Despite Email Verification

Just added Laravel Email verification to an older pre 5.7 setup that was upgraded to the latest 6.x Laravel. Registration emails are sent out and when clicked email_verified_at is populated, but there is currently one issue:

  • post registration user gets into dashboard right away and should not

NB Verification email button initially led to dashboard which then showed a 404 which was due to protected $redirectTo = '/dashboard'; missing an h

relevant routes

/*
|--------------------------------------------------------------------------
| Dashboard Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your Dashboard. Currently
| we only have a basic set up here.
|
*/

Route::get('/dashboard', '[email protected]')->name('dashboard')->middleware('auth');

/*
|--------------------------------------------------------------------------
| Verification Routes Activation
|--------------------------------------------------------------------------
|
| Verification routes to work with email verification.
| https://github.com/laravel/framework/blob/6.x/src/Illuminate/Routing/Router.php#L1205
|
*/

Auth::routes(['verify' => true]);

/*  
| -------------------------------------------------------------------------
| Custom verification Routes as Option
| -------------------------------------------------------------------------
|
| This will add custom routes like email / verify and email/resend to our application.
| https://stackoverflow.com/a/52576695
|
*/

// Auth::routes();
// Route::get('email/verify', 'Auth\[email protected]')->name('verification.notice');
// Route::get('email/verify/{id}', 'Auth\[email protected]')->name('verification.verify');
// Route::get('email/resend', 'Auth\[email protected]')->name('verification.resend');

verification controller

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Email Verification Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling email verification for any
    | user that recently registered with the application. Emails may also
    | be re-sent if the user didn't receive the original email message.
    |
    */

    use VerifiesEmails;

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

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }
}

Any ideas what I am missing here that allows user immediate access without verification?

Jan
11
2 weeks ago
Activity icon

Replied to Creating Default Object From Empty Value

Yeah, that was it. Thanks for that @bugsysha ! The form action was not in sync with the route nor Controller action.

As a side note I also do not really seem to understand :

$post = Post::where('slug', $slug)->first();

Just yet. The variable post is .. Model Post where the slug is equal to the first slug object?

Activity icon

Replied to Creating Default Object From Empty Value

I have

Route::post('blog/post/{id}/edit', '[email protected]')->name('post.update');

When i replace {id} by {slug} to Route::post('blog/post/{slug}/edit', '[email protected]')->name('post.update'); things do not change. So I guess I need a different route for this OR I need to change $post.

Activity icon

Started a new Conversation Creating Default Object From Empty Value

Using app/Http/Controllers/PostController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Post;

class PostController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $posts = Post::all();

        // https://stackoverflow.com/a/56927928/460885
        // the below is the same as return view('post.index', compact('posts'));
        // https://www.php.net/manual/en/function.compact.php
        return view('post.index')->withPosts($posts);
      }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('post.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
      $this->validate($request, [
        'title'         => 'required|min:3|max:255',
        'slug' => 'required|min:3|max:255|unique:posts',
        'body'          => 'required|min:3'
      ]);

      $post = new Post;

      $post->title = $request->title;
      $post->slug = Str::slug($request->slug);
      $post->body = $request->body;

      $post->save();

      return redirect()->route('index');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($slug)
    {
    $post = Post::where('slug', $slug)->first();

    return view('post.show')->withPost($post);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        {
            $post = Post::findOrFail($id);
      
            return view('post.edit')->withPost($post);
        }
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $slug)
    {
        $this->validate($request, [
            'title'         => 'required|min:3|max:255',
            'slug'          => 'required|min:3|max:255|unique:posts,id,' . $slug,
            'body'          => 'required|min:3'
          ]);
    
          $post = Post::where('slug', $slug)->first();
    
          $post->title = $request->title;
          $post->slug = Str::slug($request->slug);
          $post->body = $request->body;
    
          $post->save();
    
          return redirect()->route('post.show', $post->slug);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

and edit.blade.php

<!doctype html>
<html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel Tutorial</title>

        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet" type="text/css">

        <link rel="stylesheet" href="{{ asset('css/app.css') }}">

    </head>
    <body>

          <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
            <a class="navbar-brand" href="#">Laravel Tutorial</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">
              <ul class="navbar-nav mr-auto">
                <li class="nav-item active">
                  <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                </li>
              </ul>
                <a href="{{ route('post.create') }}" class="btn btn-success my-2 my-sm-0">Create Post</a>
            </div>
          </nav>
          <div class="container py-3">
          <div class="row">
            <div class="col-md-8 offset-md-2">
              <div class="card-body">
                <form method="POST" action="{{ route('post.update', $post->id) }}">
                  @csrf

                  <div class="form-group">
                    <label for="title">Title</label>
                    <input type="text" name="title" class="form-control" value="{{ $post->title }}">
                  </div>

                  <div class="form-group">
                    <label for="slug">Slug</label>
                    <input type="text" name="slug" class="form-control" value="{{ $post->slug }}">
                  </div>

                  <div class="form-group">
                    <label for="body">Description</label>
                    <textarea name="body" rows="8" cols="80" class="form-control">{{ $post->body }}</textarea>
                  </div>

                  <button type="submit" class="btn btn-primary">Update Post</button>
                </form>
              </div>
            </div>
          </div>
        </div>
    </body>
</html>

Getting

ErrorException
Creating default object from empty value

on line $post->title = $request->title; trying to update a post.

The post with the ID being edited is there in the database. So why would I have this error?

Dec
01
1 month ago
Activity icon

Replied to Lazy Loaded Files Versioning.

We use Webpack code splitting / Dynamic Imports for lazy loading components and have

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 */
mix.webpackConfig({
    output: {
        publicPath: '/',
        chunkFilename: 'js/components/[name].[hash].js',
    }
});

now in webpack.mix.js and that works with loading components using:

Vue.component('app-editor', () => import(/* webpackChunkName:"editor/app-editor"*/ './components/editor/Editor.vue'));

I only wonder how we could update version only when an update is made. Now that these are constantly generated on npm run prod we seem to generate new versions on every build.

Nov
29
1 month ago
Activity icon

Replied to How To Clear The Users Browser Cache So That The Newest Vue Deploy Loads?

the browsers will still show older cached css, but after a few clicks, i.e., say you are paginating, things auto catch up.

Is there no way with Etags or Cache-Control to deal with that and really have a clean slate. We do use Mix versioning but often some older stuff still remains behind. We want to trigger a full clean reload sometimes..

Nov
23
2 months ago
Activity icon

Replied to Vultr API Access Control

Vultr asks for a subnet, not an ip address. Seems Laravel Forge is on a Cloudflare ip range, but when I added it 104.26.0.0/20 I somehow still got blocked so I must be doing something wrong. Then I checked some again and via https://urlscan.io/ip/104.26.12.100 I saw the CIDR 104.16.0.0/12 and tried. No joy yet either. Then I found https://forge.helpscoutdocs.com/article/11-what-ip-addresses-do-i-need-to-whitelist-for-forge-to-have-access-to-my-server and added a CIDR for these two mentioned ip addresses: 159.203.0.0/16 and it still failed..

Oct
02
3 months ago
Activity icon

Started a new Conversation Load VuePress Index.html From /public/docs Without Index.html

Working on integrating VuePress for app documentation following https://medium.com/web-developer/serve-vuepress-docs-in-laravel-application-64882936842f and I can now server documentation under app.test/docs/index.html . I cannot however just load documentation using app.test/docs/.

Why is that? I prefer to just load it using my controller:

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use File;
class DocsController extends Controller
{
    public function index(Request $request, $file = 'index')
    {
        if ($file != 'index') {
            $file = $file . '/index';
        }
        return File::get(public_path() . '/docs/' . $file . '.html');
    }
}

and not loading it in a blade.php file. Tried adding base_path('public'), // for docs. to config/view.php and using this as my controller method:

public function render()
{
    // Extending view can recognize `html` file.
    View::addExtension('html', 'php');

    // public/docs/index.html.
    return view('docs.index');
}

as suggested by Yish at https://yish.dev/vuepress-integrates-into-laravel/ , but somehow did not do the trick either.

So how can I load this index.html simply calling app.test/docs/ without the extension html so without adding the filename to the browser request?

Sep
25
4 months ago
Activity icon

Started a new Conversation Dusk: Load Password Into Test Based On User Chosen

Is there an easy way in Laravel Dusk to type in a password you grab from the database based on username? I would like to leave tests a little cleaner. So I would like to pick a user, but with it load the password and then login. How can I make this happen?

Sep
24
4 months ago
Activity icon

Replied to Laravel Dusk Unable To Locate Element: ...":"body Textarea[name='email']"}

Glad you got it working . Sounds like quite a bit of extra work to make Dusk with Chrome Driver work on Vagrant. More than using Valet, that is for sure.

Activity icon

Replied to Laravel Dusk Unable To Locate Element: ...":"body Textarea[name='email']"}

Upgrade Chrome to 77:

This version of ChromeDriver only supports Chrome version 77

Sep
11
4 months ago
Activity icon

Replied to Laravel Dusk Unable To Locate Element: ...":"body Textarea[name='email']"}

Good to hear it helped someone @bespokews ! I will now further this thread figuring out what has changed since I last ran this test.

Activity icon

Replied to Laravel Dusk Unable To Locate Element: ...":"body Textarea[name='email']"}

Dusk is installed as latest version now with Chrome Driver that works with current Chrome Browser. Now I can get back to issue

) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body textarea[name='email']"}
  (Session info: headless chrome=77.0.3865.75)
  (Driver info: chromedriver=77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/[email protected]{#442}),platform=Mac OS X 10.14.6 x86_64)
Activity icon

Replied to Laravel Dusk Unable To Locate Element: ...":"body Textarea[name='email']"}

If you are using Chrome version 77, please download ChromeDriver 77.0.3865.40

And I currently seem to have 76:

Updating Google Chrome
Version 76.0.3809.132 (Official Build) (64-bit)

https://sites.google.com/a/chromium.org/chromedriver/downloads

So will try to fix that too.

Activity icon

Replied to Laravel Dusk Unable To Locate Element: ...":"body Textarea[name='email']"}

Saw this commit https://github.com/laravel/dusk/commit/1632330df524f5be92ef80c6cac2dee113f9435d .

Some markup is updated on http://chromedriver.chromium.org/home website. which break this function

preg_match('/release:.*?\?path=([\d.]+)/', $home, $matches);

should be on line 170 of vendor/laravel/dusk/src/Console/ChromeDriverCommand.php . No official update yet so just did it manually for now.

Then all good

valet @ MacMini [jasper] $ php artisan dusk:install
Dusk scaffolding installed successfully.
Downloading ChromeDriver binaries...
ChromeDriver binaries successfully installed for version 77.0.3865.40.

Only on test I got

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 77
  (Driver info: chromedriver=77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/[email protected]{#442}),platform=Mac OS X 10.14.6 x86_64)
Activity icon

Replied to Tweaking Old Migrations

Thanks @ftiersch . Thought they would not be run unless names were changed. So issue with column need must have been before addition - one single new migration we did add - to have the column there and some code not choking on it not being there. I guess I will have to dig deeper there to find out why the column was needed. Just wanted to make sure an old migration could not have been part of it on staging or production. Now it seems they have not so issue must have been with a codebase change.

Sep
10
4 months ago
Activity icon

Replied to Undo Merged Pull Request And Move It To New Branch

Okay, in the end used the Github pull request merger revert button. After that we were able to work on feature in existing branch we used as base for pull request. All easier than I thought :)

Activity icon

Started a new Conversation Laravel Dusk Unable To Locate Element: ...":"body Textarea[name='email']"}

Tried a test that I ran succesfully before

valet @ MacMini [jasper] $ php artisan dusk tests/Browser/ExampleTest.php 
PHPUnit 7.5.14 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 4.72 seconds, Memory: 28.00 MB

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body textarea[name='email']"}
  (Session info: headless chrome=76.0.3809.132)
  (Driver info: chromedriver=76.0.3809.126 (d80a294506b4c9d18015e755cee48f953ddc3f2f-refs/branch-heads/[email protected]{#1024}),platform=Mac OS X 10.14.6 x86_64)

/Users/jasper/code/site.com/valet/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:102
/Users/jasper/code/site.com/valet/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:331
/Users/jasper/code/site.com/valet/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:565
/Users/jasper/code/site.com/valet/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:204
/Users/jasper/code/site.com/valet/vendor/laravel/dusk/src/ElementResolver.php:362
/Users/jasper/code/site.com/valet/vendor/laravel/dusk/src/ElementResolver.php:340
/Users/jasper/code/site.com/valet/vendor/laravel/dusk/src/ElementResolver.php:89
/Users/jasper/code/site.com/valet/vendor/laravel/dusk/src/Concerns/InteractsWithElements.php:142
/Users/jasper/code/site.com/valet/tests/Browser/ExampleTest.php:27
/Users/jasper/code/site.com/valet/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67
/Users/jasper/code/site.com/valet/tests/Browser/ExampleTest.php:33

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

Thought perhaps I need to install things for Dusk once more on the new branch and then I had this error:

php artisan dusk:install
Dusk scaffolding installed successfully.
Downloading ChromeDriver binaries...

   ErrorException  : Undefined offset: 1

  at /Users/jasper/code/site.com/valet/vendor/laravel/dusk/src/Console/ChromeDriverCommand.php:172
    168|         $home = $this->getUrl($this->homeUrl);
    169| 
    170|         preg_match('/Latest stable release:.*?\?path=([\d.]+)/', $home, $matches);
    171| 
  > 172|         return $matches[1];
    173|     }
    174| 
    175|     /**
    176|      * Download the ChromeDriver archive.

Not sure if ErrorException : Undefined offset: 1 was a real issue or whether I needed Dusk again in the first place but the error Unable to locate element: {"method":"css selector","selector":"body textarea[name='email']"}

Any ideas?

Activity icon

Started a new Conversation Undo Merged Pull Request And Move It To New Branch

If I would like to undo a certain pull request I can do this in Github with the revert button. It will then create a revert pull request to undo the merger. Will the branch stuff was merged from then still be as it was?

This so the developer can work on it some more and do a new pull request. Just wandering and do not want to remove work done. Just want to keep it out of master a little longer.

Activity icon

Started a new Conversation Tweaking Old Migrations

We had migrations tweaked so locally we could once again run these and set up a basic database. We are now trying to figure out where a query need for a column came from and we have not figured it out. Once updated migration did add the column with $table->integer('grid_id')->unsigned();..

Questions I have on Laravel Migrations:

  1. Though old tweaked migrations would work locally from scratch, it would not work on existing setups, right?
  2. Will old migration files run on staging or production again? If no, will they still not be run when you say yes to running migrations on production?
  3. Would you fix migrations to make them work again locally with changing old migrations or would you just add new ones patching old issues (we have quite a few already..)
Sep
02
4 months ago
Activity icon

Replied to Migration Only Adds First Item Of Array

Yeah, @munazzil is not really helping here. He needs to read properly before he replies. Any feedback is welcome, as long as it is on point..

Aug
31
4 months ago
Activity icon

Replied to Migration Only Adds First Item Of Array

We do have the role model Role.php:

<?php

namespace App\Models\Auth;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    public $timestamps = false;

    public function users()
    {
        return $this->hasMany(User::class);
    }
}

as well as a user model under our Models/Auth directory. In User.php we connect things between roles and the users as well using:

  /**
  * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  */
  public function role()
  {
       return $this->belongsTo(Role::class);
  }

besides other things like user groups.

Anyways, the issue is that somehow migrations do not always run properly - not all roles added to roles table - though there are no errors. Even ran php migrate -vvv but nothing useful showed up when only one role was added.

Aug
30
4 months ago
Activity icon

Replied to Migration Only Adds First Item Of Array

This is weird. I just ran the migrations for the gazillionth time. And now all roles are added to my local Homebrew MariaDB database. Just weird..

Activity icon

Replied to Migration Only Adds First Item Of Array

That did not work and caused

 Illuminate\Database\QueryException  : SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into `roles` (`0`, `1`, `2`) values (administrator, editor, super-administrator))

  at /Users/me/code/site.com/valet/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
Activity icon

Replied to Migration Only Adds First Item Of Array

Hmm, weird. Will have to see if my local MariaDB database settings are the issue @snapey . Still getting only the first row.

@janosk the migrations just ran fine. Will also have to see if migrations after cause the two second lines / roles to be removed. Must be overlooking something here.

Aug
29
4 months ago
Activity icon

Replied to Migration Only Adds First Item Of Array

We're just using short array syntax here as possible since PHP 5.4 https://www.php.net/manual/en/migration54.new-features.php . So do not think that is the issue here. But will look into it.

Activity icon

Started a new Conversation Migration Only Adds First Item Of Array

I am using this migration on Laravel 5.8.31 to add a table roles with three roles but somehow only the first one is added and the second two are not.

public function up()
    {
        Schema::create('roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
        });

        DB::table('roles')->insert(
            [
                ['name' => 'administrator'],
                ['name' => 'editor'],
                ['name' => 'super-administrator'],
            ]
        );

Any ideas why this could be the case?

Jul
27
6 months ago
Activity icon

Commented on Using Recipes For Common Tasks

Servers for Hackers https://serversforhackers.com/scaling-laravel/forge/forge-recipes has really nice recipes to use. Missed sources for useful recipes in this episode so decided to add one.