<?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 &#8211; James Lin&#039;s Blog</title>
	<atom:link href="https://james.lin.net.nz/category/technology/programming/laravel/feed/" rel="self" type="application/rss+xml" />
	<link>https://james.lin.net.nz</link>
	<description>Just bits and pieces of my life</description>
	<lastBuildDate>Fri, 19 Jan 2018 22:42:50 +0000</lastBuildDate>
	<language>en-NZ</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.2</generator>
<site xmlns="com-wordpress:feed-additions:1">22801464</site>	<item>
		<title>Laravel for Django developers, part 3</title>
		<link>https://james.lin.net.nz/2018/01/20/laravel-for-django-developers-part-3/</link>
		<comments>https://james.lin.net.nz/2018/01/20/laravel-for-django-developers-part-3/#respond</comments>
		<pubDate>Fri, 19 Jan 2018 22:25:30 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=3992</guid>
		<description><![CDATA[During the last day of Christmas break I&#8217;ve spent a few hours trying to pick up Laravel again, from the beginning. I remember I blogged about Laravel back in 2016 (time flies!), and reading them again, I am surprised that what I thought back in 2016 still applies today. Today I am going to talk… <span class="read-more"><a href="https://james.lin.net.nz/2018/01/20/laravel-for-django-developers-part-3/">Read More &#187;</a></span>]]></description>
				<content:encoded><![CDATA[<p>During the last day of Christmas break I&#8217;ve spent a few hours trying to pick up Laravel again, from the beginning.</p>
<p>I remember I blogged about Laravel back in 2016 (time flies!), and reading them again, I am surprised that what I thought back in 2016 still applies today.</p>
<p>Today I am going to talk about some black magic I&#8217;ve encountered writing a test blog project. The bit that filling out the blog form and validating the data. Normally, when a form is posted to an URL, the controller validates the form data and throws validation exceptions if form is not validated, then the controller can redirect the browser back to the form along some error data to be displayed on the form. In Laravel, the redirecting back to the form is automatically done for you and somehow the view magically has the &#8216;errors&#8217; variable in context.</p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2018/01/20/laravel-for-django-developers-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">3992</post-id>	</item>
		<item>
		<title>Laravel for Django developers, part 2</title>
		<link>https://james.lin.net.nz/2016/02/05/laravel-for-django-developers-part-2/</link>
		<comments>https://james.lin.net.nz/2016/02/05/laravel-for-django-developers-part-2/#respond</comments>
		<pubDate>Fri, 05 Feb 2016 00:43:07 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Laravel]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=3712</guid>
		<description><![CDATA[Global functions I am seeing a lot of framework specific global functions but don&#8217;t know where they come from, such as &#8220;view()&#8221;, &#8220;redirect()&#8221; etc etc. ORM Again, as mentioned in part 1, since we are creating migration files first, then we won&#8217;t be able to define FK relationships directly point to another model. According to… <span class="read-more"><a href="https://james.lin.net.nz/2016/02/05/laravel-for-django-developers-part-2/">Read More &#187;</a></span>]]></description>
				<content:encoded><![CDATA[<h1>Global functions</h1>
<p>I am seeing a lot of framework specific global functions but don&#8217;t know where they come from, such as &#8220;view()&#8221;, &#8220;redirect()&#8221; etc etc.</p>
<h1>ORM</h1>
<p>Again, as mentioned in part 1, since we are creating migration files first, then we won&#8217;t be able to define FK relationships directly point to another model. According to the &#8220;<a href="https://laravel.com/docs/5.2/quickstart-intermediate#prepping-the-database">intermediate quickstart</a>&#8221; tutorial, you have to be a bit lower level like:</p><pre class="crayon-plain-tag">$table-&amp;gt;integer('user_id')-&amp;gt;index();</pre><p>Hang on&#8230; Would this create a FK constraint automatically like Django??</p>
<h1>Still ORM</h1>
<blockquote><p>Let&#8217;s add a few things to this model. First, we will state that the <code class=" language-php">name</code> attribute on the model should be &#8220;mass-assignable&#8221;. This will allow us to fill the <code class=" language-php">name</code> attribute when using Eloquent&#8217;s <code class=" language-php">create</code>method:</p></blockquote>
<p></p><pre class="crayon-plain-tag">class Task extends Model{
    protected $fillable = ['name'];
}</pre><p>Hmm, what? Skimming through the tutorial, so this enables you to do this:</p><pre class="crayon-plain-tag">$request-&amp;gt;user()-&amp;gt;tasks()-&amp;gt;create([
        'name' =&amp;gt; $request-&amp;gt;name,
    ]);</pre><p></p>
<h1>Still ORM &#8211; take 2</h1>
<p>In Django, when you define a ForeignKey like this</p>
<p></p><pre class="crayon-plain-tag">class User(models.Model):
  email = models.EmailField()

class Task(models.Model):
  user = models.ForeignKey(User, related_name=&quot;tasks&quot;)</pre><p></p>
<p>You can access the relationship in both ways automatically:</p><pre class="crayon-plain-tag">task.user
user.task_set.all()
user.tasks.all() // using optional defined related_name</pre><p></p>
<p>But in Laravel, it seems you have to define the relationship in each model.</p><pre class="crayon-plain-tag">class User extends Authenticatable
{
    // Other Eloquent Properties...

    /**
     * Get all of the tasks for the user.
     */
    public function tasks()
    {
        return $this-&gt;hasMany(Task::class);
    }
}

class Task extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name'];

    /**
     * Get the user that owns the task.
     */
    public function user()
    {
        return $this-&gt;belongsTo(User::class);
    }
}</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2016/02/05/laravel-for-django-developers-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">3712</post-id>	</item>
		<item>
		<title>Laravel for Django developers, part 1</title>
		<link>https://james.lin.net.nz/2016/02/05/laravel-for-django-developers-part-1/</link>
		<comments>https://james.lin.net.nz/2016/02/05/laravel-for-django-developers-part-1/#respond</comments>
		<pubDate>Fri, 05 Feb 2016 00:05:27 +0000</pubDate>
		<dc:creator><![CDATA[James Lin]]></dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://james.lin.net.nz/?p=3699</guid>
		<description><![CDATA[Project Structure After setting up the quickstart project, I feel the project structure is quite different to Django. In Django a lot of code are organised in &#8220;app&#8221; domain, but it seems to me that multi-app is not something out-of-the-box in Laravel: https://laracasts.com/discuss/channels/general-discussion/laravel-5-multi-app-or-modular-applications Instead, it seems the apps in Django is more similar to the… <span class="read-more"><a href="https://james.lin.net.nz/2016/02/05/laravel-for-django-developers-part-1/">Read More &#187;</a></span>]]></description>
				<content:encoded><![CDATA[<h1>Project Structure</h1>
<p>After setting up the <a href="https://laravel.com/docs/5.2/quickstart" target="_blank">quickstart</a> project, I feel the project structure is quite different to Django. In Django a lot of code are organised in &#8220;app&#8221; domain, but it seems to me that multi-app is not something out-of-the-box in Laravel: <a href="https://laracasts.com/discuss/channels/general-discussion/laravel-5-multi-app-or-modular-applications">https://laracasts.com/discuss/channels/general-discussion/laravel-5-multi-app-or-modular-applications</a></p>
<p>Instead, it seems the apps in Django is more similar to the &#8220;Service Providers&#8221; in Laravel.</p>
<h1>ORM</h1>
<p>While working on the <a href="https://laravel.com/docs/5.2/quickstart" target="_blank">quickstart</a> project in Laravel, it seems to me that Eloquent doesn&#8217;t generate initial migratios based on model definition.</p>
<p>In Django, you define the model, then by running &#8220;makemigration&#8221; CLI command, it will generate initial migration files to create the database table for that model.</p>
<p>According to the quickstart project, it seems to be things work the other way around, you will have to manually create the migration files by running</p><pre class="crayon-plain-tag">php artisan make:migration create_tasks_table --create=tasks</pre><p>And then create the model class by running</p><pre class="crayon-plain-tag">php artisan make:model Task</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://james.lin.net.nz/2016/02/05/laravel-for-django-developers-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<post-id xmlns="com-wordpress:feed-additions:1">3699</post-id>	</item>
	</channel>
</rss>
