<?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>Development Archives - Cube Websites</title>
	<atom:link href="https://cubewebsites.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>https://cubewebsites.com/category/development/</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>Development Archives - Cube Websites</title>
	<link>https://cubewebsites.com/category/development/</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: Setup Content Translations In Directus</title>
		<link>https://cubewebsites.com/guides/how-to-setup-content-translations-in-directus/</link>
					<comments>https://cubewebsites.com/guides/how-to-setup-content-translations-in-directus/#respond</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Thu, 05 Jan 2023 11:50:41 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Guides]]></category>
		<category><![CDATA[directus]]></category>
		<guid isPermaLink="false">https://cubewebsites.com/?p=1201</guid>

					<description><![CDATA[<p>I&#8217;ve recently been playing with Directus as a backend for some small projects. One of the great features that Directus provides is translation support which I decided to try out. Unfortunately, it when it came to the setup I couldn&#8217;t find much documentation on this so it took me a bit of read and some [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/guides/how-to-setup-content-translations-in-directus/">How To: Setup Content Translations In Directus</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I&#8217;ve recently been playing with Directus as a backend for some small projects.  One of the great features that Directus provides is translation support which I decided to try out.  Unfortunately, it when it came to the setup I couldn&#8217;t find much documentation on this so it took me a bit of read and some trial and error to figure it out. </p>



<p>This articles shares my findings and shows how easy it is to setup.</p>



<h2 class="wp-block-heading">Setup your collection</h2>



<p>Select an existing (or create a new collection) that you want translations for.  Don&#8217;t add any fields that need translations just yet!</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="372" src="https://cubewebsites.com/wp-content/uploads/2023/01/image-1024x372.png" alt="" class="wp-image-1202" srcset="https://cubewebsites.com/wp-content/uploads/2023/01/image-980x356.png 980w, https://cubewebsites.com/wp-content/uploads/2023/01/image-480x174.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw" /><figcaption class="wp-element-caption">An example of a categories collection that we want to add translations to</figcaption></figure>



<p>Next, click on Create Field and choose the &#8216;Translations&#8217; type field:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="842" height="1024" src="https://cubewebsites.com/wp-content/uploads/2023/01/image-1-842x1024.png" alt="" class="wp-image-1203"/><figcaption class="wp-element-caption">The default options for the Translation field are fine for now</figcaption></figure>



<p>If you like you can modify some of the field configuration by clicking the <code>Continue in Advanced Field Creation Mode</code>.  For example I prefer using UpperCamelCase for my table names, so I modified the <code>languages</code> table name to <code>Languages</code></p>



<h2 class="wp-block-heading">Setup Translation Fields</h2>



<p>Once you&#8217;ve done that go back to the <code>Data Model</code> screen.  Here you&#8217;ll see a new hidden collection, in my case <code>Categories Translations</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="84" src="https://cubewebsites.com/wp-content/uploads/2023/01/image-3-1024x84.png" alt="" class="wp-image-1205" srcset="https://cubewebsites.com/wp-content/uploads/2023/01/image-3-980x80.png 980w, https://cubewebsites.com/wp-content/uploads/2023/01/image-3-480x39.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw" /></figure>



<p>Click into the <code>Categories_Translations</code> table, and within this collection add all the fields for <code>Categories</code> that need translations. e.g.:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="527" src="https://cubewebsites.com/wp-content/uploads/2023/01/image-4-1024x527.png" alt="" class="wp-image-1206" srcset="https://cubewebsites.com/wp-content/uploads/2023/01/image-4-980x504.png 980w, https://cubewebsites.com/wp-content/uploads/2023/01/image-4-480x247.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw" /><figcaption class="wp-element-caption">The id, Categories_id, Languages_id fields are created automatically when you setup the translations on Categories.  I added Name and Description</figcaption></figure>



<h2 class="wp-block-heading">Add Translated Content</h2>



<p>Now, go to the Content menu and choose your collection.  You&#8217;ll see the fields you&#8217;ve added to the Translations table appear with the option to fill them out in different languages.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="928" src="https://cubewebsites.com/wp-content/uploads/2023/01/image-5-1024x928.png" alt="" class="wp-image-1207" srcset="https://cubewebsites.com/wp-content/uploads/2023/01/image-5-980x888.png 980w, https://cubewebsites.com/wp-content/uploads/2023/01/image-5-480x435.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw" /><figcaption class="wp-element-caption">Example of adding translated content</figcaption></figure>



<p>Here you can use the Translations input to select a language, and then use the input fields below to populate the content in your selected Language.  There&#8217;s even a split view which is very handy if you&#8217;re translating content from one language to another.</p>



<h2 class="wp-block-heading">Managing Languages</h2>



<p>You can control which Languages appear by modifying the entries in the Languages collection.  By default Directus populates that table with 8 common languagues.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="867" height="1024" src="https://cubewebsites.com/wp-content/uploads/2023/01/image-6-867x1024.png" alt="" class="wp-image-1208" srcset="https://cubewebsites.com/wp-content/uploads/2023/01/image-6-867x1024.png 867w, https://cubewebsites.com/wp-content/uploads/2023/01/image-6-480x567.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 867px, 100vw" /></figure>



<p>Hopefully this demonstrates how easy it is to add translated content in Directus.  Of course, if there&#8217;s fields that don&#8217;t need translation you just add them in the parent table &#8211; in this case the <code>Categories</code> collection.</p>



<p></p>
<p>The post <a href="https://cubewebsites.com/guides/how-to-setup-content-translations-in-directus/">How To: Setup Content Translations In Directus</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/guides/how-to-setup-content-translations-in-directus/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: Check Which Docker Container Is Using A Port</title>
		<link>https://cubewebsites.com/guides/how-to-check-which-docker-container-is-using-a-port/</link>
					<comments>https://cubewebsites.com/guides/how-to-check-which-docker-container-is-using-a-port/#respond</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Tue, 03 Jan 2023 12:30:23 +0000</pubDate>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[tools]]></category>
		<guid isPermaLink="false">https://cubewebsites.com/?p=1197</guid>

					<description><![CDATA[<p>This morning I had a Docker service fail to start. On inspection of the error, it turned out it was because the port was in use by another service. In this particular case, my Docker service was trying to use port 8029 so that&#8217;s what I&#8217;ve used in the examples below. This searches through your [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/guides/how-to-check-which-docker-container-is-using-a-port/">How To: Check Which Docker Container Is Using A Port</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This morning I had a Docker service fail to start.  On inspection of the error, it turned out it was because the port was in use by another service.  In this particular case, my Docker service was trying to use port 8029 so that&#8217;s what I&#8217;ve used in the examples below.</p>



<pre class="wp-block-code"><code>docker ps | grep 8029</code></pre>



<p>This searches through your docker containers, and finds any that are running on port 8029.  The output should look like this:</p>



<pre class="wp-block-code"><code>fec0c35f0b2d directus/directus:latest "docker-entrypoint.s…" 15 minutes ago Up 5 minutes 127.0.0.1:8029->8055/tcp directus-example</code></pre>



<p>In the above example you can see that port 8029 was identified to be in use by the directus-example container.  It turns out I did a test install of Directus on that port, and then forgot to delete it.</p>



<p>Stop the docker container:</p>



<pre class="wp-block-code"><code>docker stop fec0c35f0b2d</code></pre>



<p>The container ID (<code>fec0c35f0b2d</code>) used above is from the first command which provided the container ID</p>



<p>Delete the docker container. In my case I no longer needed this Directus container, so I deleted the container too.  If you need to keep your container, then just change its configuration to run on a different port that doesn&#8217;t clash.</p>



<pre class="wp-block-code"><code>docker rm fec0c35f0b2d</code></pre>



<p>With this complete, I was able to start the Docker container that&#8217;s actually supposed to be running on port 8029 with no issues.</p>



<p>In my case I knew that the port would be used by Docker because I use that port range for Docker only.  If you don&#8217;t know for sure that it&#8217;s Docker using the port, then you can use the following to check which service is using the port.  Note that you will need sudo access to run this.</p>



<pre class="wp-block-code"><code>sudo netstat -tulpn | grep 8029</code></pre>



<p>The output from this should tell you which service is using that port.</p>
<p>The post <a href="https://cubewebsites.com/guides/how-to-check-which-docker-container-is-using-a-port/">How To: Check Which Docker Container Is Using A Port</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/guides/how-to-check-which-docker-container-is-using-a-port/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>
		<item>
		<title>Getting Started With Laravel and Ember</title>
		<link>https://cubewebsites.com/development/ember/getting-started-laravel-ember/</link>
					<comments>https://cubewebsites.com/development/ember/getting-started-laravel-ember/#comments</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Mon, 07 Mar 2016 18:56:43 +0000</pubDate>
				<category><![CDATA[Ember]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ember]]></category>
		<category><![CDATA[laravel]]></category>
		<guid isPermaLink="false">https://cubewebsites.com/?p=461</guid>

					<description><![CDATA[<p>Introduction This guide will show you how to setup a new project using Ember and Laravel, JSON-API and token based authentication.  The deployed version of your application will be a Laravel backend which serves up the Ember frontend using a Laravel route. Software At the time of writing the tools used are: Laravel 5.1 (LTS) [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/development/ember/getting-started-laravel-ember/">Getting Started With Laravel and Ember</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>This guide will show you how to setup a new project using Ember and Laravel, JSON-API and token based authentication.  The deployed version of your application will be a Laravel backend which serves up the Ember frontend using a Laravel route.</p>
<p><strong>Software</strong></p>
<p>At the time of writing the tools used are:</p>
<ul>
<li><a href="https://laravel.com/docs/5.1">Laravel 5.1</a> (LTS)</li>
<li><a href="http://emberjs.com/builds/">Ember 2.4.1</a> (LTS) with <a href="http://ember-cli.com/">Ember-CLI 2.4.1</a></li>
<li><a href="https://github.com/dingo/api">Dingo API</a> 1.0.0 (beta)</li>
<li><a href="https://github.com/tymondesigns/jwt-auth">Tymon jwt-auth</a> 0.5.9</li>
<li><a href="https://github.com/simplabs/ember-simple-auth">ember-simple-auth</a> 1.0.1</li>
<li><a href="https://github.com/jpadilla/ember-simple-auth-token">ember-simple-auth-token</a> 1.0.0</li>
</ul>
<p><strong>Prerequisites</strong></p>
<ol>
<li><a href="http://ember-cli.com/">Ember CLI 2.4.1</a></li>
<li><a href="https://laravel.com/docs/5.1#installation">Laravel Requirements</a></li>
<li><a href="https://getcomposer.org/">Composer</a></li>
<li><a href="https://git-scm.com/">Git</a> or any other VCS that you prefer</li>
</ol>
<p><span id="more-461"></span></p>
<h2><strong>Initial Setup</strong></h2>
<p>The basic project structure will be a <strong>backend</strong> directory for the Laravel part, and a <strong>frontend</strong> directory for Ember.</p>
<pre>#create a directory called sample-project
mkdir sample-project
# go into the sample-project directory
cd sample-project
# make the project a Git project
git init .</pre>
<p>For .gitignore files I prefer using <a href="http://gitignore.io/">gitignore.io</a> which creates a <code>.gitignore</code> file for the software that you use.  Just generate one that matches your needs, I use the following: <code>OSX, Composer, Laravel, PHPStorm, Vagrant</code> but you can customise for your own needs.  Just generate and add this to the root of your sample project e.g.</p>
<pre>wget "https://www.gitignore.io/api/osx%2Ccomposer%2Claravel%2Cphpstorm%2Cvagrant" -O .gitignore</pre>
<p>NOTE: I don&#8217;t like that gitignore&#8217;s Laravel setup excludes the full storage directory &#8211; which can cause problems during deployment.  Instead I manually remove the following line from the .gitignore file and use the .gitignore files already provided by Laravel in each storage subdirectory.</p>
<p><code>storage/</code></p>
<p>It also selectively excludes certain PHPStorm files (.idea) whereas I prefer ignoring the full .idea directory:</p>
<pre># Add .idea to the .gitignore file
echo ".idea" &gt;&gt; .gitignore</pre>
<h2><strong>Laravel (Backend) Setup<br />
</strong></h2>
<p>I prefer to use the LTS releases of Laravel, so will be installing version 5.1</p>
<pre># Install Laravel 5.1 to a directory called backend
composer create-project laravel/laravel backend "5.1.*"
# Switch into the backend (Laravel) directory
cd backend</pre>
<p>Your current project structure should now look like this:</p>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-15.26.03.png" rel="attachment wp-att-463"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-463" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-15.26.03.png" alt="Screen Shot 2016-03-06 at 15.26.03" width="137" height="57" /></a></p>
<pre># Delete the .git directory from backend as we already have our Git project setup in the project root
# Make sure you are in the backend directory (don't delete .git in your project root directory)
rm -Rf .git</pre>
<pre># Add all the Laravel files and commit the project
git add .
git commit -a -m "Added Laravel 5.1"</pre>
<p>Add your database configuration to the <code>.env</code> file by updating the following lines:</p>
<pre>DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret</pre>
<pre># Migrate the default Laravel tables
php artisan migrate</pre>
<h3><strong>Install Dingo API</strong></h3>
<p>The <a href="https://github.com/dingo/api">Dingo API</a> package has <a href="https://github.com/dingo/api/wiki">comprehensive documentation available</a> but for the sake of this guide I&#8217;ll go through a quick setup.  I highly recommend you read through the documentation and configuration so that you can make your API work appropriately for you.</p>
<pre># Install the Dingo API package
composer require dingo/api:1.0.x@dev</pre>
<p>Add the Dingo API service provider class to the list of Laravel providers (<code>config/app.php</code>)</p>
<pre>Dingo\Api\Provider\LaravelServiceProvider::class,</pre>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.35.50.png" rel="attachment wp-att-465"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-465" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.35.50-300x221.png" alt="Screen Shot 2016-03-06 at 19.35.50" width="300" height="221" srcset="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.35.50-300x221.png 300w, https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.35.50.png 316w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Publish the Dingo API config file</p>
<pre>php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"</pre>
<p>Add some basic config options to the <code>.env</code> file</p>
<pre>API_PREFIX=api
API_VERSION=v1
API_DEBUG=true</pre>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.36.26.png" rel="attachment wp-att-466"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-466" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.36.26.png" alt="Screen Shot 2016-03-06 at 19.36.26" width="164" height="116" /></a></p>
<pre># Git commit the changes (Dingo API Installation)
git add .
git commit -a -m "Installed Dingo API"</pre>
<h3><strong>Install Tymon JWT-Auth</strong></h3>
<p>The JWT-Auth token package is only required if JWT (JSON Web Tokens) is an authentication method that you plan to use in your application.  This tutorials assuems that you will be using it, but if you&#8217;re not then just skip the appropriate parts.</p>
<p>This package also has <a href="https://github.com/tymondesigns/jwt-auth/wiki">great documentation available</a> that you&#8217;re advised to read through to make sure you set it up in a way that works for you but the few steps below will get you started</p>
<pre># Install Tymon JWT-Auth
composer require tymon/jwt-auth</pre>
<p>Add the JWTAuth Service provider to the providers section in <code>config/app.php</code>:</p>
<pre>Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,</pre>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.37.21.png" rel="attachment wp-att-467"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-467" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.37.21-300x87.png" alt="Screen Shot 2016-03-06 at 19.37.21" width="300" height="87" srcset="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.37.21-300x87.png 300w, https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.37.21.png 367w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Add the JWTAuth facade to the aliases section in <code>config/app.php</code></p>
<pre>'JWTAuth' =&gt; 'Tymon\JWTAuth\Facades\JWTAuth',</pre>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.37.28.png" rel="attachment wp-att-468"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-468" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.37.28-300x95.png" alt="Screen Shot 2016-03-06 at 19.37.28" width="300" height="95" srcset="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.37.28-300x95.png 300w, https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.37.28.png 369w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<pre># Publish the JWTAuth config file
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"
# Generate JWT Auth secret key
php artisan jwt:generate</pre>
<p>Now that the JWT Auth and API packages are installed, we need to configure the API to use JWT for it&#8217;s authentication method.  Luckily this can be done very easily in the API config file located in <code>config/api.php</code></p>
<p>Find the following section:</p>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.42.42.png" rel="attachment wp-att-469"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-469" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.42.42-300x159.png" alt="Original API Auth Configuration" width="300" height="159" srcset="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.42.42-300x159.png 300w, https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.42.42.png 467w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>And add the following within the auth array:</p>
<pre>'jwt' =&gt; 'Dingo\Api\Auth\Provider\JWT',</pre>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.44.56.png" rel="attachment wp-att-470"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-470" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.44.56.png" alt="Dingo API using JWT Auth" width="277" height="64" /></a></p>
<pre>git add .
git commit -a -m "JWT auth package installed"</pre>
<h3><strong>Using JSON API</strong></h3>
<p>JSON API is a standard for APIs that use JSON data and has been the default adapter setting in Ember since version 2.0.  In order to make the API return JSON API formatted data we just need to configure Dingo API to use the JsonApiSerializer that it comes bundled with.</p>
<p>in <code>app/Providers/AppServiceProvider.php</code></p>
<p>First add the following use statements:</p>
<pre>use Dingo\Api\Transformer\Adapter\Fractal;
use Illuminate\Support\ServiceProvider;
use League\Fractal\Manager;
use League\Fractal\Serializer\JsonApiSerializer;</pre>
<p>Add the following to the boot() method within this service provider:</p>
<pre>// API uses JSON API
$this-&gt;app['Dingo\Api\Transformer\Factory']-&gt;setAdapter(function ($app) {
     $fractal = new Manager();
     $fractal-&gt;setSerializer(new JsonApiSerializer());
     return new Fractal($fractal);
});</pre>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.54.05.png" rel="attachment wp-att-471"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-471" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.54.05-300x270.png" alt="Dingo API JSON API serializer" width="300" height="270" srcset="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.54.05-300x270.png 300w, https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-19.54.05.png 511w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<pre>git add .
git commit -a -m "API uses JSON API serializer"</pre>
<h3><strong>Setting up the Laravel Router</strong></h3>
<p>Below you&#8217;ll find the template of the Laravel routes file (<code>app/Http/routes.php</code>) that which you can download from my <a href="https://github.com/cubewebsites/laravel-ember-starter/blob/master/laravel/app/Http/routes.php">laravel-ember-starter repo</a></p>
<pre>&lt;?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

// API Routes come first
$api = app('Dingo\Api\Routing\Router');
$api-&gt;version('v1',function($api){
    header('Access-Control-Allow-Origin: http://localhost:4200');
    header('Access-Control-Allow-Headers: Origin, Content-Type, Authorization');
    header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, PATCH, DELETE');

    // API
    $api-&gt;group(['namespace'=&gt;'App\Http\Controllers\Api'],function($api){
        // Auth
        $api-&gt;post('auth/login','Auth\AuthController@postLogin');
        $api-&gt;post('auth/token-refresh','Auth\AuthController@refreshToken');
        $api-&gt;post('users','Auth\UsersController@store');

        // Protected methods (require auth)
        $api-&gt;group(['middleware'=&gt;'api.auth'],function($api){
            
        });

        // Public methods
        
    });
});

// Catchall - Displays Ember app
Route::any('{catchall}',function(){
    return view('index');
})-&gt;where('catchall', '(.*)');
</pre>
<p>Few notes on the above routes.php file:</p>
<ol>
<li><code>http://localhost:4200</code> is the default address when using Ember serve to develop your app</li>
<li>All the API requests are handled first</li>
<li>All non-API requests are caught by the final catch all rule, which returns the index view</li>
<li>The index view will return the Ember application</li>
<li>I prefer to use App\Http\Controllers\Api as my root namespace for API controllers, but you can amend this as necessary</li>
</ol>
<h3><strong>Authentication</strong></h3>
<p>As you can see in the above routes file, we have two Authentication routes:</p>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-21.12.24.png" rel="attachment wp-att-474"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-474" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-21.12.24.png" alt="Laravel JWT Auth Routes" width="422" height="37" srcset="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-21.12.24.png 422w, https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-06-at-21.12.24-300x26.png 300w" sizes="(max-width: 422px) 100vw, 422px" /></a></p>
<p>To implement these methods we&#8217;ll first need to create the <code>app/Http/Controllers/Api/Auth/AuthController.php</code> file and setup the authentication methods</p>
<pre>&lt;?php
namespace app\Http\Controllers\Api\Auth;


use App\Http\Controllers\Controller;
use Dingo\Api\Http\Request;
use Dingo\Api\Routing\Helpers;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;

class AuthController extends Controller
{

    use Helpers;

    public function postLogin(Request $request)
    {
        // grab credentials from the request
        $credentials = $request-&gt;only('email', 'password');

        try {
            // attempt to verify the credentials and create a token for the user
            if (! $token = \JWTAuth::attempt($credentials)) {
                throw new UnauthorizedHttpException("Email address / password do not match");
            }
        } catch (JWTException $e) {
            // something went wrong whilst attempting to encode the token
            throw new HttpException("Unable to login");
        }

        // all good so return the token
        return $this-&gt;response-&gt;array(compact('token'));
    }

    public function refreshToken(Request $request)
    {
        $token  =   $request-&gt;get('token');
        if(!$token)
        {
            return $this-&gt;response-&gt;errorBadRequest('Token not provided');
        }
        try {
            $token  =   \JWTAuth::refresh($token);
        }
        catch(TokenInvalidException $e) {
            return $this-&gt;response-&gt;errorForbidden('Invalid token provided');
        }
        return $this-&gt;response-&gt;array(compact('token'));
    }

}</pre>
<p>The <code>login</code> method will get the email and password from the request, try to authenticate and then return errors on failure (Dingo handles exceptions) and a token on success<br />
<code>refreshToken</code> gets the token from the request, and then attempts to refresh the token (generating a new token).</p>
<p>Full contents of the controller including traits and use statements can be downloaded from <a href="https://github.com/cubewebsites/laravel-ember-starter/blob/master/laravel/app/Http/Controllers/Api/Auth/AuthController.php">my laravel-ember-starter repo</a></p>
<pre>git add .
git commit -a -m "Added Authentication methods"</pre>
<h3><strong>Laravel Finishing Touches</strong></h3>
<p>In <code>app/Http/Kernel.php</code> comment out or delete the line:</p>
<pre>\App\Http\Middleware\VerifyCsrfToken::class,</pre>
<p>If you want to create a test user (change the credentials to whatever you want) to test your authentication</p>
<pre># Create a dummy user
php artisan tinker
App\User::create(['email'=&gt;'<a class="linkification-ext" title="Linkification: mailto:email@domain.com','password'=" href="mailto:email@domain.com','password'=">email@domain.com','password'=</a>&gt;bcrypt('password')]);
exit</pre>
<pre>git add .
git commit -a -m "Laravel Setup complete"</pre>
<h3>Laravel Summary</h3>
<p>That&#8217;s it with the Laravel setup for now.  Whilst there&#8217;s quite a few steps the idea is quite simple:</p>
<ol>
<li>Install Laravel</li>
<li>Add API support</li>
<li>Add JWT setup</li>
<li>Setup the API to use JSON API</li>
<li>Add authentication methods</li>
</ol>
<h2>Ember Frontend Setup</h2>
<p>Now that the API setup is ready we focus on creating a new Ember project to use as the frontend.</p>
<h3>Initialize Project with Ember-CLI</h3>
<pre># go back up to the project root directory
cd ..
# create a new Ember project called 'frontend'
ember new frontend
# go into the 'frontend' directory
cd frontend
# delete the .git folder created by Ember (in the frontend directory - don't delete the one in your project root)
rm -Rf .git
# add the Ember project to our Git repo
git add .
git commit -a -m "Added Ember project"</pre>
<p>When developing applications I use Vagrant for serving the Laravel app, and the Ember-CLI built in server.  This gives me two URLs:</p>
<ol>
<li><code>http://myapp.local</code> &#8211; which goes to the Laravel application running on Vagrant</li>
<li><code>http://localhost:4200</code> &#8211; the default URL for the Ember application using ember serve</li>
</ol>
<p>For the application to work, we need to make the Ember application aware of the Laravel URL so that we can make API requests to it.  To do this I specify the API url as a config setting in Ember.  In <code>config/environment.js</code> add the following line (replace the URL with your Laravel application URL):</p>
<pre>ENV.apiBaseUrl = 'http://sample-project.local';</pre>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-07-at-12.00.46.png" rel="attachment wp-att-489"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-489" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-07-at-12.00.46.png" alt="Updated Ember environment file" width="467" height="329" srcset="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-07-at-12.00.46.png 467w, https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-07-at-12.00.46-300x211.png 300w" sizes="(max-width: 467px) 100vw, 467px" /></a></p>
<p>You&#8217;ll notice in that config file that there&#8217;s sections where you can specify environment specific settings (e.g. development and production) which means you can set the above option separately for each environment.</p>
<h3>Add Authentication Packages</h3>
<p>For authentication with Ember we&#8217;ll use Ember Simple Auth base package, with Ember Simple Auth Token since we need JWT support.</p>
<pre># Install Ember Simple Auth
ember install ember-simple-auth
# Install Ember Simple Auth Token
ember install ember-simple-auth-token</pre>
<p>Then to configure the Auth packages add the following to config/environment.js:</p>
<pre>ENV['ember-simple-auth'] = {
  authorizer: 'authorizer:token'
};
ENV['ember-simple-auth-token'] = {
  refreshAccessTokens: true,
  timeFactor: 1000,
  refreshLeeway: 300,
  serverTokenEndpoint: ENV.apiBaseUrl + '/api/auth/login',
  serverTokenRefreshEndpoint: ENV.apiBaseUrl + '/api/auth/token-refresh',
  identificationField: 'email'
};</pre>
<p><a href="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-07-at-18.43.25.png" rel="attachment wp-att-506"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-506" src="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-07-at-18.43.25.png" alt="Ember Simple Auth Token Configuration" width="450" height="241" srcset="https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-07-at-18.43.25.png 450w, https://cubewebsites.com/wp-content/uploads/2016/03/Screen-Shot-2016-03-07-at-18.43.25-300x161.png 300w" sizes="(max-width: 450px) 100vw, 450px" /></a><br />
You can update the options to suit your requirements if necessary</p>
<h3>Login</h3>
<pre># generate the login route
ember g route login</pre>
<p>Create a simple form in the login template <code>app/templates/login.hbs</code></p>
<pre>{{#if errorMessage}}
    {{errorMessage}}
{{/if}}
&lt;form {{action 'authenticate' on='submit'}}&gt;
  &lt;label for="identification"&gt;Login&lt;/label&gt;
  {{input id='identification' placeholder='Enter Login' value=identification}}
  &lt;label for="password"&gt;Password&lt;/label&gt;
  {{input id='password' placeholder='Enter Password' type='password' value=password}}
  &lt;button type="submit"&gt;Login&lt;/button&gt;
&lt;/form&gt;</pre>
<p>Make the route available only when the user isn&#8217;t logged in, and clear the errors when the user goes to a different page by editing the login route file in <code>app/routes/login.js</code></p>
<pre>import Ember from 'ember';
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';

export default Ember.Route.extend(UnauthenticatedRouteMixin,{
    resetController(controller,isExiting)
    {
        if(isExiting){
            controller.set('errorMessage', '');
        }
    }
});</pre>
<pre># Create the login controller
ember generate controller login</pre>
<p>Handle authentication attempts in the login controller <code>app/controllers/login.js</code></p>
<pre>import Ember from 'ember';

export default Ember.Controller.extend({
  session: Ember.inject.service(),

  actions: {
    authenticate: function() {
      var credentials = this.getProperties('identification', 'password'),
        authenticator = 'authenticator:jwt';

      this.get('session').authenticate(authenticator, credentials).catch((message) =&gt; {
        this.set('errorMessage', message.message);
      });
    }
  }
});</pre>
<h3>Authenticating API Requests</h3>
<p>At this point authentication should be working properly, but we still need to configure Ember to send the token in API requests to access protected endpoints.  In order to do this we&#8217;ll extend the Ember JSON API adapter and configure it to use the Token Authorizer from Ember Simple Auth Token.</p>
<pre># Create the adapter
ember g adapter application</pre>
<p>Update the adapter in <code>app/adapters/application.js</code></p>
<pre>import DS from 'ember-data';
import ENV from 'frontend/config/environment';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';

export default DS.JSONAPIAdapter.extend(DataAdapterMixin,{
	host: ENV.apiBaseUrl,
	namespace:'api',
	authorizer: 'authorizer:token',
	handleResponse: function(status, headers, payload){
		// If the response is 422 (Unprocessable Entity) then format the errors into JSONAPI format
		if(status === 422 &amp;&amp; payload.errors){
			let error_response	=	[];
			for(var key in payload.errors) {
				error_response.push({id:key,title:payload.errors[key][0]});
			}
			return new DS.InvalidError(error_response);
		}
		return this._super(...arguments);
	}
});</pre>
<p>As well as setting the authorizer the above adapter also sets the following options:</p>
<ol>
<li><code>host</code> &#8211; tells the adapter to make all requests to the apiBaseUrl that we specified in the config</li>
<li><code>namespace</code> &#8211; Use the &#8216;api&#8217; namespace for all requests (to match all the Laravel route structure)</li>
<li><code>handleResponse</code> &#8211; format the errors for 422 errors</li>
</ol>
<h3>Logout</h3>
<p>Logout is an action that can be accessed from any page with the application, so we&#8217;ll handle the logout action in the application controller.</p>
<pre># create application controller
ember g controller application</pre>
<p>Create the invalidateSession method in the application controller: app/controllers/application.js</p>
<pre>import Ember from 'ember';

export default Ember.Controller.extend({
	session: Ember.inject.service('session'),
	actions: {
		invalidateSession() {
			this.get('session').invalidate();
		}
	}
});</pre>
<p>Of course you&#8217;ll want to add the logout link in your application template <code>app/templates/application.hbs</code></p>
<pre>&lt;ul&gt;
    {{#if session.isAuthenticated}}
        &lt;li&gt;&lt;a {{action 'invalidateSession'}}&gt;Logout&lt;/a&gt;&lt;/li&gt;
    {{else}}
        &lt;li&gt;{{#link-to 'login'}}Login{{/link-to}}&lt;/li&gt;
        &lt;li&gt;{{#link-to 'register'}}Register{{/link-to}}&lt;/li&gt;
    {{/if}}
&lt;/ul&gt;</pre>
<pre># git commit
git add .
git commit -a -m "Ember authentication implemented"</pre>
<h3>Registration</h3>
<p>If your application requires user registration then use the steps below, and if you don&#8217;t need registration just comment out the line from backend/app/Http/routes.php:</p>
<pre>$api-&gt;post('users','Auth\UsersController@store');</pre>
<h4>Backend Setup</h4>
<p>We&#8217;ve already defined a route for creating new users in the backend/app/Http/routes.php file:</p>
<pre>$api-&gt;post('users','Auth\UsersController@store');</pre>
<p>The next step is to create a new controller with the Laravel project directory: </p>
<pre># Switch to the 'backend' directory
cd ../backend</pre>
<p>Create <code>app/Http/Controllers/Api/Auth/UsersController.php</code> and populate the store action:</p>
<pre>&lt;?php
/**
 * Created by PhpStorm.
 * User: ash
 * Date: 02/03/2016
 * Time: 10:06
 */

namespace app\Http\Controllers\Api\Auth;


use App\Http\Controllers\Controller;
use App\User;
use Dingo\Api\Exception\StoreResourceFailedException;
use Dingo\Api\Http\Request;
use Dingo\Api\Routing\Helpers;

class UsersController extends Controller
{
    use Helpers;

    public function store(Request $request)
    {
        $data   =   $request-&gt;get('data')['attributes'];
        $validator  =   \Validator::make($data,[
            'email'     =&gt;  'required|email|unique:users',
            'password'  =&gt;  'required'
        ]);
        if($validator-&gt;fails()){
            throw new StoreResourceFailedException('Invalid user data',$validator-&gt;errors());
        }
        User::create(['email'=&gt;$data['email'],'password'=&gt;bcrypt($data['password'])]);
        return $this-&gt;response-&gt;noContent();
    }
}</pre>
<p>The submitted data is validated, and detailed errors returned if validation fails. Otherwise we send back a success response with no content, which the Ember app will use to notify the user that registration is successful and that they can now login</p>
<p>The next step is to create a registration route and a user model:</p>
<pre># Switch back to the 'frontend' directory
cd ../frontend
ember g route register
ember g model user email:string password:string</pre>
<p>Setup the registration template in <code>app/templates/register.hbs</code></p>
<pre>{{#if registered}}
    &lt;h1&gt;Registered!&lt;/h1&gt;
    &lt;p&gt;Registration was successful.  You can {{link-to 'now login' 'login'}} with the credentials you registered with.&lt;/p&gt;
{{else}}
{{#if errorMessage}}
    {{errorMessage}}
{{/if}}
&lt;form {{action 'register' on='submit'}}&gt;
    &lt;p&gt;Create a New Account&lt;/p&gt;
    &lt;label for="identification"&gt;Email&lt;/label&gt;
    {{input id='identification' placeholder='Email Address' value=model.email type='email'}}
    &lt;label for="password"&gt;Password&lt;/label&gt;
    {{input id='password' placeholder='Enter Password' type='password' value=model.password}}
    &lt;button type="submit"&gt;Register&lt;/button&gt;
&lt;/form&gt;
{{/if}}</pre>
<p>The registration route needs a couple of updates to make it accessible to unauthenticated users, and to clear the error messages when the user leaves the page so update <code>app/routes/register.js</code></p>
<pre>import Ember from 'ember';
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';

export default Ember.Route.extend(UnauthenticatedRouteMixin,{
    model() {
      return this.store.createRecord('user');
    },
    resetController(controller,isExiting)
    {
        if(isExiting){
            controller.get('model').rollbackAttributes();
            controller.set('errorMessage', '');
        }
    }
});</pre>
<p>Handle registration attempts in the register controller: <code>app/controllers/register.js</code></p>
<pre># Create the register controller
ember g controller register</pre>
<pre>import Ember from 'ember';

export default Ember.Controller.extend({
    session: Ember.inject.service(),
    registered: false,
    actions: {
        register(){
            let self = this;
            this.get('model').save().then(()=&gt;{
                self.set('registered',1);
            }).catch((error)=&gt;{
                this.set('errorMessage',"Registration failed.");
            });
        }
    }
});
</pre>
<h3>Setup Complete</h3>
<p>That concludes the setup for the project. You have working logins and registration, a JSON API with authenticated routes and an Ember application ready for your custom code.</p>
<h3>Deployments</h3>
<p>You might have noticed that during the Laravel setup we setup a catchall route that returns an index view but we didn&#8217;t actually create the view. This is because it&#8217;s not required during development &#8211; we use Ember serve to load our Ember application instead.</p>
<p>Once you&#8217;re ready to deploy your project to production or staging you&#8217;ll need to build the Ember application and copy across the files into the Laravel public directory. I&#8217;ve created a simple script that I use for staging (and a similar script for production deployments). The idea is to have a production branch in the Git repo which is deployed on the server.</p>
<p>You can use the script below and modify it to suit your needs:</p>
<pre># create the publish-staging script
touch publish-staging.sh
# make the publish script executable
chmod a+x publish-staging.sh</pre>
<p>Set the contents of the publish script <code>publish-staging.sh</code></p>
<pre>#!/usr/bin/env bash

# PUBLISH STAGING

# make sure we're in the master branch
git checkout master
git add .
git commit -a -m "Pre-publish commit"
git push
# switch to staging branch
git checkout staging
# merge master into staging
git merge master
# build the Ember application
cd frontend &amp;&amp; ember build --environment staging &amp;&amp; cd ..;
# clear public
rm -Rf backend/public/assets;
rm -Rf backend/public/fonts;
rm -Rf backend/public/index.html;
rm -Rf backend/public/crossdomain.xml;
# copy the new Ember build into the Laravel application
cp -R frontend/dist/assets backend/public
cp -R frontend/dist/fonts backend/public
cp -R frontend/dist/index.html backend/resources/views/index.blade.php
cp -R frontend/dist/crossdomain.xml backend/public
# git commit
git add .
git commit -a -m "Fresh Staging build"
git push origin staging

# switch back to master
git checkout master</pre>
<p>This publish script goes in the project root and just make sure you stop your ember server before running it to prevent conflicts. The other thing to be aware of is uncommitted changes &#8211; as you can see the script above will switch to master and commit all uncommitted changes, which will cause problems if you&#8217;re currently working on a feature branch with uncommitted changes.</p>
<h2>Summary</h2>
<p>That&#8217;s a pretty full on guide to setting up a project that uses a Laravel backend and Ember as the frontend. Once complete you can get on with the meat and bones of the application.</p>
<h2>Code Availability</h2>
<p>You can find the files created and used within this application in <a href="https://github.com/cubewebsites/laravel-ember-starter" target="_blank">my laravel-ember-starter project repo</a>. If you like I can make the whole sample app available on Github so that you can have everything served to you without having to work through all the steps yourself. I&#8217;m reluctant to do this upfront as there&#8217;s a lot going on in the tutorial and I&#8217;d advise you to read through and understand what&#8217;s going on and make any neccessary changes as you see fit.</p>
<p>Feel free to leave comments and suggestions for improvements in the discussion area below.</p>
<p>The post <a href="https://cubewebsites.com/development/ember/getting-started-laravel-ember/">Getting Started With Laravel and Ember</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/development/ember/getting-started-laravel-ember/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>[GUIDE] Find and Replace Markdown Image URLs in PHP</title>
		<link>https://cubewebsites.com/development/php/guide-find-and-replace-markdown-image-urls-in-php/</link>
					<comments>https://cubewebsites.com/development/php/guide-find-and-replace-markdown-image-urls-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Mon, 29 Feb 2016 21:40:55 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[markdown]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[regex]]></category>
		<guid isPermaLink="false">https://cubewebsites.com/?p=453</guid>

					<description><![CDATA[<p>The Code // Inline Style Images $content = preg_replace_callback('/!\[(.*)\]\s?\((.*)(.png&#124;.gif&#124;.jpg&#124;.jpeg)(.*)\)/',function($match){ return str_replace('your_search_term','your_replacement',$match[0]); },$content); // Reference Style Images $content = preg_replace_callback('/\[(.*)\]:\s?(.*)(.png&#124;.gif&#124;.jpg&#124;.jpeg)/',function($match){ return str_replace('your_search_term','your_replacement',$match[0]); },$content); Why Would You Need This? I had to use the above code in a Laravel project where the content is entered into a frontend form in Markdown format. When saving the data in [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/development/php/guide-find-and-replace-markdown-image-urls-in-php/">[GUIDE] Find and Replace Markdown Image URLs in PHP</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>The Code</strong></p>
<pre>// Inline Style Images
$content    =   preg_replace_callback('/!\[(.*)\]\s?\((.*)(.png|.gif|.jpg|.jpeg)(.*)\)/',function($match){
    return str_replace('your_search_term','your_replacement',$match[0]);
},$content);

// Reference Style Images
$content    =   preg_replace_callback('/\[(.*)\]:\s?(.*)(.png|.gif|.jpg|.jpeg)/',function($match){
    return str_replace('your_search_term','your_replacement',$match[0]);
},$content);</pre>
<p><strong>Why Would You Need This?</strong></p>
<p>I had to use the above code in a Laravel project where the content is entered into a frontend form in Markdown format.  When saving the data in my Laravel backend app I wanted to replace the image URL with a placeholder so that the sites URL itself isn&#8217;t hardcoded into the database.  When displaying the data, the placeholder is replaced with the URL of the site again.  This means that if the URL ever changes (different dev environment, staging, production etc) then the images would still load providing that the files still existed in the same location on the server.</p>
<p>Your use case might be different but the above regex should provide you with a decent starting point to actually find the image tags (both inline and reference style) and then manipulate them however you wish.</p>
<p>The post <a href="https://cubewebsites.com/development/php/guide-find-and-replace-markdown-image-urls-in-php/">[GUIDE] Find and Replace Markdown Image URLs in PHP</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/development/php/guide-find-and-replace-markdown-image-urls-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>FIX: Vagrant php-memcached error</title>
		<link>https://cubewebsites.com/development/fix-vagrant-php-memcached-error/</link>
					<comments>https://cubewebsites.com/development/fix-vagrant-php-memcached-error/#respond</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Thu, 14 Jan 2016 16:57:16 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[vagrant]]></category>
		<guid isPermaLink="false">http://www.cubewebsites.com/blog/?p=450</guid>

					<description><![CDATA[<p>I normally use PuPHPet to configure my Vagrant boxes. On my latest box using CentOS 5.6 the setup worked normally, but when trying to run my application I was getting the Class &#8216;Memcache&#8217; not found error. Usually this is a simple fix, just go in and type: sudo yum install -y php-memcached However, this time [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/development/fix-vagrant-php-memcached-error/">FIX: Vagrant php-memcached error</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I normally use PuPHPet to configure my Vagrant boxes.<br />
On my latest box using CentOS 5.6 the setup worked normally, but when trying to run my application I was getting the Class &#8216;Memcache&#8217; not found error.</p>
<p>Usually this is a simple fix, just go in and type:</p>
<p><code>sudo yum install -y php-memcached</code></p>
<p>However, this time round the above was giving me the following error:</p>
<p><code>Transaction Check Error:<br />
  file /usr/lib64/libhashkit.so.2.0.0 conflicts between attempted installs of libmemcached-last-libs-1.0.18-2.el6.remi.x86_64 and libmemcached10-1.0.16-1.ius.centos6.x86_64<br />
  file /usr/lib64/libmemcached.so.11.0.0 conflicts between attempted installs of libmemcached-last-libs-1.0.18-2.el6.remi.x86_64 and libmemcached10-1.0.16-1.ius.centos6.x86_64<br />
  file /usr/lib64/libmemcachedutil.so.2.0.0 conflicts between attempted installs of libmemcached-last-libs-1.0.18-2.el6.remi.x86_64 and libmemcached10-1.0.16-1.ius.centos6.x86_64</code></p>
<p>After smashing my head against the desk a few times during numerous attempts at installing the module, reprovisioning the vagrant box and anything else I could think of doing to fix it, I tried something that hadn&#8217;t occurred to me before; to install the dependency it was complaining about first.</p>
<p>Using the following commands fixed my issue, and should also work for you:<br />
<code><br />
sudo yum install -y libmemcached-last<br />
sudo yum install -y php-memcached<br />
sudo service php-fpm restart<br />
</code></p>
<p>Hope this helps!</p>
<p>The post <a href="https://cubewebsites.com/development/fix-vagrant-php-memcached-error/">FIX: Vagrant php-memcached error</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/development/fix-vagrant-php-memcached-error/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>FIX: Vagrant Pecl Error</title>
		<link>https://cubewebsites.com/development/tools/fix-vagrant-pecl-error/</link>
					<comments>https://cubewebsites.com/development/tools/fix-vagrant-pecl-error/#respond</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Wed, 05 Aug 2015 16:36:49 +0000</pubDate>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[puphpet]]></category>
		<category><![CDATA[vagrant]]></category>
		<guid isPermaLink="false">http://www.cubewebsites.com/blog/?p=445</guid>

					<description><![CDATA[<p>I just came across an issue where I updated my vagrant config and tried to provision the box, but it kept erroring out with the following error: ==&#62; default: Error: printf "\\n" &#124; pecl -d preferred_state=stable install pecl_http returned 1 instead of one of [0] ==&#62; default: Error: /Stage[main]/Puphpet_php/Puphpet::Php::Pecl[pecl_http]/Php::Pecl::Module[pecl_http]/Exec[pecl-pecl_http]/returns: change from notrun to 0 failed: [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/development/tools/fix-vagrant-pecl-error/">FIX: Vagrant Pecl Error</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I just came across an issue where I updated my vagrant config and tried to provision the box, but it kept erroring out with the following error:</p>
<pre>==&gt; default: Error: printf "\\n" | pecl -d preferred_state=stable install pecl_http returned 1 instead of one of [0]
==&gt; default: Error: /Stage[main]/Puphpet_php/Puphpet::Php::Pecl[pecl_http]/Php::Pecl::Module[pecl_http]/Exec[pecl-pecl_http]/returns: change from notrun to 0 failed: printf "\\n" | pecl -d preferred_state=stable install pecl_http returned 1 instead of one of [0]
==&gt; default: Warning: /Stage[main]/Puphpet_php/Service[php5-fpm]: Skipping because of failed dependencies</pre>
<p>In order to fix this I logged into the server using SSH, and then manually ran the install pecl_http command that it was trying to run in the above error message.  In doing so I got a different error:</p>
<pre>$ sudo pecl -d preferred_state=stable install pecl_http</pre>
<pre>pecl/pecl_http requires package "pecl/raphf" (version &gt;= 1.1.0), installed version is 1.0.4
No valid packages found
install failed</pre>
<p>It turns out that a pecl dependency was out of date and so it couldn&#8217;t install the pecl_http package.  In order to fix it I just ran the pecl upgrade command.</p>
<pre>vagrant up
vagrant ssh
sudo pecl upgrade</pre>
<p>After running the above, I tried my vagrant provision again, and hey presto! Everything was working again as normal</p>
<p>The post <a href="https://cubewebsites.com/development/tools/fix-vagrant-pecl-error/">FIX: Vagrant Pecl Error</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/development/tools/fix-vagrant-pecl-error/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>FIX: Telegram Webhooks Not Working</title>
		<link>https://cubewebsites.com/guides/fix-telegram-webhooks-not-working/</link>
					<comments>https://cubewebsites.com/guides/fix-telegram-webhooks-not-working/#comments</comments>
		
		<dc:creator><![CDATA[Cube Websites]]></dc:creator>
		<pubDate>Sat, 04 Jul 2015 11:40:35 +0000</pubDate>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[telegram]]></category>
		<guid isPermaLink="false">http://www.cubewebsites.com/blog/?p=438</guid>

					<description><![CDATA[<p>Telegram messenger recently released an API that lets you easily create bots for their platform.  After deciding to have a bit of a play with it, I found that I had an issue where the webhooks would not send any updates to my server with no apparent error. The Problem I made all the following [&#8230;]</p>
<p>The post <a href="https://cubewebsites.com/guides/fix-telegram-webhooks-not-working/">FIX: Telegram Webhooks Not Working</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Telegram messenger recently released an API that lets you easily create bots for their platform.  After deciding to have a bit of a play with it, I found that I had an issue where the webhooks would not send any updates to my server with <em>no apparent error.</em></p>
<p><strong>The Problem</strong></p>
<p>I made all the following checks:</p>
<ol>
<li>Valid SSL certificate</li>
<li>Webhook successfully registered using the Telegram setWebhook method</li>
<li>The method responded properly when I sent a test request using a REST service tester</li>
<li>Server access logs &#8211; look like Telegram had never even hit the server</li>
</ol>
<p><strong>The Solution</strong></p>
<p>After a full day of searching, testing and bashing my head against the keyboard, I found <a href="https://www.reddit.com/r/Telegram/comments/3b4z1k/bot_api_recieving_nothing_on_a_correctly/csjmj8y">this thread</a> on Reddit, where the user described a problem where a full chained certificate was required on the server, not just the server certificate.</p>
<p>To create chained certificate you&#8217;ll need to have a look at what instructions your certificate issuer provides.</p>
<p>In my case the certificate being used was a Comodo PositiveSSL, for which I downloaded all the certificates that they sent, which contained:</p>
<ul>
<li>Root CA Certificate &#8211; AddTrustExternalCARoot.crt</li>
<li>Intermediate CA Certificate &#8211; COMODORSAAddTrustCA.crt</li>
<li>Intermediate CA Certificate &#8211; COMODORSADomainValidationSecureServerCA.crt</li>
<li>Your PositiveSSL Certificate &#8211; my_domain.crt</li>
</ul>
<p>I had to combine them all into a file in the following order:</p>
<ul>
<li>my_domain.crt</li>
<li>COMODORSADomainValidationSecureServerCA.crt</li>
<li>COMODORSAAddTrustCA.crt</li>
<li>AddTrustExternalCARoot.crt</li>
</ul>
<p>For the example above the command would have been:</p>
<pre>cat my_domain.crt COMODORSADomainValidationSecureServerCA.crt AddTrustExternalCARoot.crt COMODORSAAddTrustCA.crt &gt; bundle.crt</pre>
<p>After that it was just a case of uploading the new bundle.crt to my server, updating the nginx config, and hey presto, within minutes I was receiving all the responses for my webhooks</p>
<p>The post <a href="https://cubewebsites.com/guides/fix-telegram-webhooks-not-working/">FIX: Telegram Webhooks Not Working</a> appeared first on <a href="https://cubewebsites.com">Cube Websites</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://cubewebsites.com/guides/fix-telegram-webhooks-not-working/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
