<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Laravel Archives - Cube Websites</title>
	<atom:link href="https://cubewebsites.com/category/development/laravel/feed/" rel="self" type="application/rss+xml" />
	<link>https://cubewebsites.com/category/development/laravel/</link>
	<description>web design and development</description>
	<lastBuildDate>Tue, 06 Jun 2023 14:14:47 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://cubewebsites.com/wp-content/uploads/2019/04/cropped-favicon-32x32.png</url>
	<title>Laravel Archives - Cube Websites</title>
	<link>https://cubewebsites.com/category/development/laravel/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>HOW TO: SETUP PEST PHP 2 WITH LARAVEL 10+</title>
		<link>https://cubewebsites.com/development/laravel/how-to-setup-pest-php-2-with-laravel-10/</link>
					<comments>https://cubewebsites.com/development/laravel/how-to-setup-pest-php-2-with-laravel-10/#respond</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Tue, 06 Jun 2023 14:14:46 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[testing]]></category>
		<guid isPermaLink="false">https://cubewebsites.com/?p=1221</guid>

					<description><![CDATA[<p>This guide shows quick steps on how to use the current version of the PEST PHP Testing Framework with Laravel 10. This guide has been written with the current latest versions of the libraries: InsTALLATION The above should output the installed PEST version, which in my case is 2.6.2 The output here should be the [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/development/laravel/how-to-setup-pest-php-2-with-laravel-10/">HOW TO: SETUP PEST PHP 2 WITH LARAVEL 10+</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This guide shows quick steps on how to use the current version of the PEST PHP Testing Framework with Laravel 10.</p>



<p>This guide has been written with the current latest versions of the libraries:</p>



<ul class="wp-block-list">
<li>PEST 2.6.2</li>



<li>Laravel 10.13.1 </li>
</ul>



<h2 class="wp-block-heading">InsTALLATION</h2>



<ul class="wp-block-list">
<li>Install Laravel using any of their methods detailed in the <a href="https://laravel.com/docs/10.x/installation" target="_blank" rel="noreferrer noopener nofollow">Official Documentation</a></li>



<li>Install PEST using Composer.  The flags in this command are very important as it&#8217;s likely that you&#8217;ll have conflicting dependencies and this will take care of that for you:</li>
</ul>



<pre class="wp-block-code"><code>composer require pestphp/pest --dev --with-all-dependencies</code></pre>



<ul class="wp-block-list">
<li>Install the Laravel Plugin for PEST</li>
</ul>



<pre class="wp-block-code"><code>composer require pestphp/pest-plugin-laravel --dev</code></pre>



<ul class="wp-block-list">
<li>At this stage the installation should be complete and running the following you can verify that things are working as they should</li>
</ul>



<pre class="wp-block-code"><code>./vendor/bin/pest --version</code></pre>



<p>The above should output the installed PEST version, which in my case is 2.6.2</p>



<pre class="wp-block-code"><code>php artisan pest</code></pre>



<p>The output here should be the &#8216;Available commands for the &#8220;pest&#8221; namespace</p>



<h2 class="wp-block-heading">Installation Troubleshooting</h2>



<pre class="wp-block-code"><code>Info from https://repo.packagist.org: #StandWithUkraine
./composer.json has been updated
Running composer update pestphp/pest
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - pestphp/pest&#91;v0.1.0, ..., v0.2.4] require php ^7.3 -> your php version (8.1.19) does not satisfy that requirement.
    - pestphp/pest&#91;v0.3.0, ..., v0.3.19, v1.0.0, ..., v1.4.0] require nunomaduro/collision ^5.0 -> found nunomaduro/collision&#91;v5.0.0, ..., v5.11.0] but it conflicts with your root composer.json require (^7.0).
    - pestphp/pest&#91;v1.5.0, ..., v1.17.0] require nunomaduro/collision ^5.4.0 -> found nunomaduro/collision&#91;v5.4.0, ..., v5.11.0] but it conflicts with your root composer.json require (^7.0).
    - pestphp/pest&#91;v1.18.0, ..., v1.21.1] require nunomaduro/collision ^5.4.0|^6.0 -> found nunomaduro/collision&#91;v5.4.0, ..., v5.11.0, v6.0.0, ..., v6.4.0] but it conflicts with your root composer.json require (^7.0).
    - pestphp/pest&#91;v1.21.2, ..., v1.22.1] require nunomaduro/collision ^5.10.0|^6.0 -> found nunomaduro/collision&#91;v5.10.0, v5.11.0, v6.0.0, ..., v6.4.0] but it conflicts with your root composer.json require (^7.0).
    - pestphp/pest&#91;v1.22.2, ..., v1.22.5] require nunomaduro/collision ^5.11.0|^6.3.0 -> found nunomaduro/collision&#91;v5.11.0, v6.3.0, v6.3.1, v6.3.2, v6.4.0] but it conflicts with your root composer.json require (^7.0).
    - pestphp/pest&#91;v1.22.6, ..., v1.23.0] require nunomaduro/collision ^5.11.0|^6.4.0 -> found nunomaduro/collision&#91;v5.11.0, v6.4.0] but it conflicts with your root composer.json require (^7.0).
    - pestphp/pest v2.6.2 conflicts with phpunit/phpunit >10.2.0.
    - pestphp/pest v2.6.1 conflicts with phpunit/phpunit >10.1.3.
    - pestphp/pest&#91;v2.5.3, ..., v2.6.0] conflict with phpunit/phpunit >10.1.2.
    - pestphp/pest&#91;v2.5.1, ..., v2.5.2] conflict with phpunit/phpunit >10.1.1.
    - pestphp/pest v2.5.0 conflicts with phpunit/phpunit >10.1.0.
    - pestphp/pest&#91;v2.3.0, ..., v2.4.0] conflict with phpunit/phpunit >10.0.19.
    - pestphp/pest&#91;v2.2.1, ..., v2.2.3] conflict with phpunit/phpunit >10.0.18.
    - pestphp/pest&#91;v2.0.2, ..., v2.2.0] conflict with phpunit/phpunit >10.0.17.
    - pestphp/pest v2.0.1 conflicts with phpunit/phpunit >10.0.16.
    - phpunit/phpunit is locked to version 10.2.1 and an update of this package was not requested.
    - Root composer.json requires pestphp/pest * -> satisfiable by pestphp/pest&#91;v0.1.0, ..., v0.3.19, v1.0.0, ..., v1.23.0, v2.0.1, ..., v2.6.2].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require pestphp/pest:*" to figure out if any version is installable, or "composer require pestphp/pest:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.</code></pre>



<p>If you see the error above, check the composer require command that you ran.  You&#8217;ll need the flags displayed above to allow Composer to update your dependencies to satisfy PEST and Laravel.</p>



<h2 class="wp-block-heading">Configuration</h2>



<p>After installation you&#8217;ll find you can run the existing Laravel Example tests with the Pest command.  This is because Pest is built on top of PHPUnit in a progressive manner.</p>



<p>If you try writing your own test e.g. consider the following:</p>



<pre class="wp-block-code"><code>&lt;?php

it('makes an example request', function () {
    $response = $this->get('/');
    $response->assertStatus(200);
});
</code></pre>



<p>You may get an error like the following:</p>



<pre class="wp-block-code"><code>  FAILED  Tests\Feature\ExampleRequestTest > it get an example request                                                                                                                                                                                                 Error
  Call to undefined method Tests\Feature\ExampleRequestTest::get(). Did you forget to use the &#91;uses()] function? Read more at: https://pestphp.com/docs/configuring-tests

  at tests/Feature/ExampleRequestTest.php:4
      1▕ &lt;?php
      2▕
      3▕ it('get an example request', function () {
  ➜   4▕     $response = $this->get('/');
      5▕     $response->assertStatus(200);
      6▕ });
      7▕

  1   tests/Feature/ExampleRequestTest.php:4


  Tests:    2 failed, 2 passed (2 assertions)
  Duration: 0.08s</code></pre>



<p>This is because Pest is not yet configured to use the Laravel TestCase which includes the additional methods such as <code>get</code>, <code>post</code>, <code>actingAs</code> etc. </p>



<p>To solve this we create a new file:</p>



<pre class="wp-block-code"><code>./tests/Pest.php</code></pre>



<p>Add the following into the file</p>



<pre class="wp-block-code"><code>&lt;?php
uses(\Tests\TestCase::class)->in('Feature');
uses(\Tests\TestCase::class)->in('Unit');</code></pre>



<p>This tells Pest to use the Laravel TestCase in your Feature and Unit tests and makes the additional methods available to your Pest tests.</p>



<p>You can now run the test again, and this time it should run without the error</p>



<h2 class="wp-block-heading">Database Setup (Optional)</h2>



<p>Unit tests test blocks of code and so don&#8217;t require the Laravel application to start.  However, with Feature tests you&#8217;ll find that they do boot the Laravel application and everything within &#8211; including a database connection.  By default, it will connect to whatever you Database Connection is defined as in your <code>.env</code> file which means your tests end up writing to your dev database.  This may be fine, but I prefer keeping a separate databases for Dev and Testing.</p>



<p>There&#8217;s a number of ways to do this including using SQLite, but I find it&#8217;s better to run the same database type as I will be using in production to avoid any unforeseen issues.  The easiest way to do this is to create a second database and then configure the connection using a <code>.env.testing</code> file &#8211; more information on this is available in the <a href="https://laravel.com/docs/10.x/testing#the-env-testing-environment-file" target="_blank" rel="noreferrer noopener nofollow">Laravel Docs</a>.</p>



<h2 class="wp-block-heading">Summary</h2>



<p>I hope this guide helps anyone looking for a current installation of Laravel and Pest.</p>
<p>The post <a href="https://cubewebsites.com/development/laravel/how-to-setup-pest-php-2-with-laravel-10/">HOW TO: SETUP PEST PHP 2 WITH LARAVEL 10+</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/development/laravel/how-to-setup-pest-php-2-with-laravel-10/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>HOW TO: Using Laravel with Directus 9</title>
		<link>https://cubewebsites.com/development/laravel/how-to-using-laravel-with-directus-9/</link>
					<comments>https://cubewebsites.com/development/laravel/how-to-using-laravel-with-directus-9/#respond</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Tue, 03 Jan 2023 15:21:16 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[directus]]></category>
		<category><![CDATA[laravel]]></category>
		<guid isPermaLink="false">https://cubewebsites.com/?p=1199</guid>

					<description><![CDATA[<p>If you need to use Directus with Laravel then this guide will take you through the steps needed to get connected in just a few minutes. The general idea is to use a composer package to interact with Directus. We&#8217;ll register it in our AppServiceProvider which means we can call a pre-configured instance anywhere in [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/development/laravel/how-to-using-laravel-with-directus-9/">HOW TO: Using Laravel with Directus 9</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you need to use Directus with Laravel then this guide will take you through the steps needed to get connected in just a few minutes.</p>



<p>The general idea is to use a composer package to interact with Directus.  We&#8217;ll register it in our AppServiceProvider which means we can call a pre-configured instance anywhere in our app using dependency-injection.</p>



<p><strong>In Directus</strong></p>



<ul class="wp-block-list">
<li>It&#8217;s advisable to create a new role for your Laravel Application.  To make it easy to track I give it the name &#8216;laravel-app&#8217;</li>



<li>Create a new user for your Laravel Application and assign it the new Role you just created</li>



<li>On the Edit User screen, find the &#8216;Token&#8217; field.  Generate a token and <strong>make a note of it somewhere</strong></li>
</ul>



<p><strong>In Laravel</strong></p>



<ul class="wp-block-list">
<li>Now switch to your Laravel app.  For this integration, I&#8217;m using a composer package from https://github.com/alantiller/directus-php-sdk</li>



<li>Install the package:</li>
</ul>



<pre class="wp-block-code"><code>composer require alantiller/directus-php-sdk</code></pre>



<ul class="wp-block-list">
<li>In your <code>.env</code> file add the following:</li>
</ul>



<pre class="wp-block-code"><code>DIRECTUS_URL=https://directus.example.com
DIRECTUS_TOKEN=-YOURTOKEN</code></pre>



<ul class="wp-block-list">
<li>Replace the Url with your actual Directus URL</li>



<li>Replace YOURTOKEN with the Token you generated for your Laravel user in Directus</li>



<li>In config/services.php add the following:</li>
</ul>



<pre class="wp-block-code"><code>'directus' =&gt; &#91;<br>    'url'   =&gt; env('DIRECTUS_URL'),<br>    'token' =&gt; env('DIRECTUS_TOKEN'),<br>],</code></pre>



<p>In app/providers/AppServiceProvider.php add the following to the <code>register()</code> method</p>



<pre class="wp-block-code"><code>$this-&gt;app-&gt;singleton(Directus::class, function ($app) {<br>    $directus = new Directus($app&#91;'config']&#91;'services']&#91;'directus']&#91;'url'],'');<br>    $directus-&gt;auth_token($app&#91;'config']&#91;'services']&#91;'directus']&#91;'token']);<br>    return $directus;<br>});</code></pre>



<p>In your code you&#8217;ll be able to now use Directus with the standard dependency injection.  You can find examples on how to use the <a href="https://github.com/alantiller/directus-php-sdk" target="_blank" rel="noreferrer noopener nofollow">alantiller/directus-php-sdk package on Github</a>.</p>



<p>Example:</p>



<pre class="wp-block-code"><code>php artisan make:command DirectusTest</code></pre>



<p>In the <code>handle</code> method of the generated command:</p>



<pre class="wp-block-code"><code>&lt;?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class DirectusTest extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'directus:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(\Slations\DirectusSdk\Directus $directus)
    {
        dd($directus->users_me());
    }
}</code></pre>



<p>Call the command:</p>



<pre class="wp-block-code"><code>php artisan directus:tset</code></pre>



<p>The output should show you details of the Laravel App user you added on Directus.  Once it&#8217;s working delete the command.</p>



<p>This is all it takes to have a fully working Directus integration with Laravel.  The package does most of the work, but registering it in your AppServiceProvider means you&#8217;ll get a connected instance whenever you need to use it instead of having to instantiate it.</p>



<p>Note that this application uses an application token which is tied to a single user.  If you need multi-user support then the package supports <code>login</code> so you can authenticate users and use their auth token.</p>
<p>The post <a href="https://cubewebsites.com/development/laravel/how-to-using-laravel-with-directus-9/">HOW TO: Using Laravel with Directus 9</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/development/laravel/how-to-using-laravel-with-directus-9/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>HOW TO: Using Laravel with Vite on MAMP</title>
		<link>https://cubewebsites.com/development/laravel/how-to-using-laravel-with-vite-on-mamp/</link>
					<comments>https://cubewebsites.com/development/laravel/how-to-using-laravel-with-vite-on-mamp/#respond</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Wed, 28 Dec 2022 11:34:42 +0000</pubDate>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[mamp]]></category>
		<category><![CDATA[vite]]></category>
		<guid isPermaLink="false">https://cubewebsites.com/?p=1186</guid>

					<description><![CDATA[<p>I recently needed to help someone out who was using MAMP on a MacBook Pro on a Laravel 9 project. The project was configured to: The Problem When running the default project with yarn run dev and accessing the project in the browser via the hostname configured in MAMP, the hot reload feature was not [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/development/laravel/how-to-using-laravel-with-vite-on-mamp/">HOW TO: Using Laravel with Vite on MAMP</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I recently needed to help someone out who was using MAMP on a MacBook Pro on a Laravel 9 project.</p>



<p>The project was configured to:</p>



<ul class="wp-block-list">
<li>run on MAMP</li>



<li>the MAMP host was configured to use SSL</li>



<li>Laravel 9</li>



<li>Vite</li>



<li>InertiaJS</li>
</ul>



<h2 class="wp-block-heading">The Problem</h2>



<p>When running the default project with <code>yarn run dev</code> and accessing the project in the browser via the hostname configured in MAMP, the hot reload feature was not working and the network and console tabs in Developer Tools were polluted with lots of 404 errors about the failure to connect to the Vite Ping URL e.g. <code>__vite_ping</code> to which it keeps trying to reconnect to.</p>



<h2 class="wp-block-heading">How to fix</h2>



<p>You have to configure Vite to run on https.  This can be done in a number of ways, but the easiest is to use the <a href="https://www.npmjs.com/package/@vitejs/plugin-basic-ssl" target="_blank" rel="noreferrer noopener nofollow">@vitejs/plugin-basic-ssl</a> plugin.  It&#8217;s really easy to get started:</p>



<ol class="wp-block-list">
<li>Add the plugin to your project
<ul class="wp-block-list">
<li>with yarn: <code>yarn add --dev @vitejs/plugin-basic-ssl</code></li>



<li>with npm: <code>npm i @vitejs/plugin-basic-ssl</code></li>
</ul>
</li>



<li>Open the <code>vite.config.js</code> file in your Laravel project</li>



<li>Import the plugin at the top of the file:
<ul class="wp-block-list">
<li><code>import basicSsl from '@vitejs/plugin-basic-ssl'</code></li>
</ul>
</li>



<li>Enable the plugin using the defineConfig block e.g.</li>
</ol>



<pre class="wp-block-preformatted">export default {
  plugins: [
    basicSsl()
  ]
}</pre>



<p>Note: you might already have other plugins or config options in the <code>defineConfig</code> block, but you just need to make sure you add the called to <code>basicSsl()</code> in the plugins section.</p>



<p>After this when you run your project using <code>yarn run dev</code> it will provide you with a Local URL e.g.</p>



<pre class="wp-block-code"><code>11:15:06 &#91;vite] vite.config.js changed, restarting server...
11:15:06 &#91;vite] server restarted.

  > Local: https://localhost:3000/
  > Network: use `--host` to expose</code></pre>



<p>Open that Local URL in your browser and you&#8217;ll receive an SSL warning.  Accept the risks to accept the SSL certificate generated by the plugin.</p>



<p>Once that&#8217;s done when you visit your application dev URL, you&#8217;ll see all the Vite 404 errors have disappeared and you&#8217;re left with one neat little log that tells you Vite is now connected.</p>



<pre class="wp-block-code"><code>&#91;vite] connecting... <a href="https://127.0.0.1:3000/src/client/client.ts">client.ts:16:8</a>
&#91;vite] connected. client.ts:53:14</code></pre>



<p>Hope this helps!</p>
<p>The post <a href="https://cubewebsites.com/development/laravel/how-to-using-laravel-with-vite-on-mamp/">HOW TO: Using Laravel with Vite on MAMP</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/development/laravel/how-to-using-laravel-with-vite-on-mamp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
