<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hamid Semix</title>
    <description>The latest articles on DEV Community by Hamid Semix (@hsemix).</description>
    <link>https://dev.to/hsemix</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F128628%2F059584be-dd2d-4b4b-a9a8-3b0ddfe5ffd9.jpg</url>
      <title>DEV Community: Hamid Semix</title>
      <link>https://dev.to/hsemix</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hsemix"/>
    <language>en</language>
    <item>
      <title>Build a Double-Entry Wallet in Laravel with Laravanced Wallet</title>
      <dc:creator>Hamid Semix</dc:creator>
      <pubDate>Sat, 14 Nov 2026 14:41:16 +0000</pubDate>
      <link>https://dev.to/hsemix/build-a-double-entry-wallet-in-laravel-with-laravanced-wallet-26fb</link>
      <guid>https://dev.to/hsemix/build-a-double-entry-wallet-in-laravel-with-laravanced-wallet-26fb</guid>
      <description>&lt;p&gt;Need wallet functionality in your Laravel app? If you’re building deposits, transfers, fees, payment approvals, or scheduled payments, handling balances yourself can quickly become complicated.&lt;/p&gt;

&lt;p&gt;Advanced Laravel Wallet is a Laravel package for building double-entry, multi-account wallets. It gives you a ledger-oriented foundation for common payment flows, while letting your application decide how those flows fit into your product.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why double-entry?&lt;/strong&gt;&lt;br&gt;
A balance by itself tells you what an account has now—but not necessarily how it got there. In a double-entry ledger, transfers are the source of truth, and balances are a projection that can be reconciled against the transaction history.&lt;/p&gt;

&lt;p&gt;That approach is useful when you need more than "subtract from one user, add to another." For example, a payment might involve a fee account, an authorization step, or a later chargeback.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you can build&lt;/strong&gt;&lt;br&gt;
Laravanced Wallet includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple account types, including user and system accounts&lt;/li&gt;
&lt;li&gt;Accounts owned by any Eloquent model&lt;/li&gt;
&lt;li&gt;Transfer types with amount and frequency limits&lt;/li&gt;
&lt;li&gt;Fixed and percentage fees, with configurable payer and receiver&lt;/li&gt;
&lt;li&gt;Payment previews designed to match what the eventual payment books&lt;/li&gt;
&lt;li&gt;Authorization flows that reserve funds while a payment is pending&lt;/li&gt;
&lt;li&gt;Chargebacks for a transaction or an individual transfer&lt;/li&gt;
&lt;li&gt;Scheduled and recurring payments, including installment plans&lt;/li&gt;
&lt;li&gt;Paginated history, totals, and ledger balances as of a date&lt;/li&gt;
&lt;li&gt;Events and commands for processing scheduled payments and reconciling balances&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Install it&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require hsemix/laravanced-wallet
php artisan migrate
php artisan vendor:publish --tag=wallet-config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Publishing the configuration is optional. The package requires the PHP &lt;code&gt;ext-bcmath&lt;/code&gt; extension. Monetary values use &lt;code&gt;decimal(20,4)&lt;/code&gt; storage and string-based arithmetic rather than floats.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Give a model a wallet&lt;/strong&gt;&lt;br&gt;
Add the HasWallet trait to any Eloquent model that should own wallet accounts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Hsemix&lt;/span&gt;\&lt;span class="nc"&gt;AdvancedWallet&lt;/span&gt;\&lt;span class="nc"&gt;Concerns&lt;/span&gt;\&lt;span class="nc"&gt;HasWallet&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;HasWallet&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, after configuring an account type, open an account for a user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;openAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'wallet'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Accounts are polymorphic, so they don’t have to belong only to a User model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configure transfers and make a payment&lt;/strong&gt;&lt;br&gt;
The package uses account types and transfer types to describe which accounts can participate in a payment. For example, you might configure a user wallet, a system treasury, and a transfer type for deposits.&lt;/p&gt;

&lt;p&gt;Once those are configured, a payment can move funds from the system account to a user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Wallet&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'from'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'system'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'to'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'type'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'treasury.deposit'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'amount'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also transfer between wallet owners:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$alice&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;payTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nv"&gt;$bob&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'wallet.transfer'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'rent'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Payment types use the format "account_type.transfer_type". The from and to values can be an account, an owner model, 'system', or an account ID.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Preview before booking&lt;/strong&gt;&lt;br&gt;
Sometimes you need to show the user what a payment will do before they confirm it. Use preview() to inspect the proposed payment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$preview&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Wallet&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'from'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$alice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'to'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$bob&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'type'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'wallet.transfer'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'amount'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package’s preview flow is designed to match what perform() books, which is especially useful when fees affect the final amounts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add fees and approval flows&lt;/strong&gt;&lt;br&gt;
Fees can be configured as fixed amounts or percentages, with options for who pays and who receives them. For example, a percentage fee can be charged to the source account and credited to a system account.&lt;/p&gt;

&lt;p&gt;For payments that need approval, the package supports pending payments that reserve funds. You can then authorize, deny, or cancel the payment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Wallet&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;payments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;authorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Other available actions:&lt;/span&gt;
&lt;span class="nc"&gt;Wallet&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;payments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;deny&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$transaction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$reviewer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Reason'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Wallet&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;payments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The wallet balance API can report the balance, reserved amount, and available amount:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;walletBalance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'wallet'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Scheduled payments and chargebacks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can schedule payments as installments—for example, splitting a total principal across three monthly payments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Wallet&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;scheduled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'from'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$alice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'to'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$bob&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'type'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'wallet.plan'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'amount'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'installments'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'immediate'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'first_date'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'2026-02-01'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'frequency_unit'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'month'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package also supports chargebacks for a whole transaction or a single transfer, including fees. Scheduled payments can support flat or annual amortized interest, with optional full reservation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Give it a try&lt;/strong&gt;&lt;br&gt;
Laravanced Wallet can help you get started with ledger-based wallet functionality without building every payment mechanism from scratch. Explore the &lt;a href="https://hsemix.github.io/laravanced-wallet/" rel="noopener noreferrer"&gt;Docs&lt;/a&gt; for setup details and the available APIs, then adapt the account and transfer types to your application.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>opensource</category>
      <category>wallet</category>
    </item>
    <item>
      <title>What can FFI, preloading and Typed Properties do for us in php?</title>
      <dc:creator>Hamid Semix</dc:creator>
      <pubDate>Mon, 29 Jul 2019 15:28:30 +0000</pubDate>
      <link>https://dev.to/hsemix/what-can-ffi-preloading-and-typed-properties-do-for-us-in-php-3joc</link>
      <guid>https://dev.to/hsemix/what-can-ffi-preloading-and-typed-properties-do-for-us-in-php-3joc</guid>
      <description>&lt;p&gt;With the introduction of ffi, preloading and typed properties in php &amp;gt;= 7.4, should we now assume that php is fit for developing desktop applications or even more? &lt;/p&gt;

</description>
      <category>php</category>
    </item>
    <item>
      <title>Getting started with yuga-framework part 3 (Querying the database and more)</title>
      <dc:creator>Hamid Semix</dc:creator>
      <pubDate>Fri, 22 Mar 2019 11:55:25 +0000</pubDate>
      <link>https://dev.to/hsemix/getting-started-with-yuga-framework-part-3-querying-the-database-and-more-4j85</link>
      <guid>https://dev.to/hsemix/getting-started-with-yuga-framework-part-3-querying-the-database-and-more-4j85</guid>
      <description>

&lt;p&gt;In today's tutorial, I am going to take you through how to comment on a post that is already in the database,&lt;br&gt;
this requires to first query the database for that post, then attach a comment to it and then save the changes, so without any further ado, let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  First we need to query the database for a given post say with id &lt;strong&gt;1&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Yuga comes with an &lt;strong&gt;&lt;em&gt;ORM&lt;/em&gt;&lt;/strong&gt; that might by handy at database manipulation, so, that's what we will use for querying our post from the database but first, lets create a route for accessing our post. Let's open &lt;code&gt;routes/web.php&lt;/code&gt; file to create our route.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// routes/web.php&lt;/span&gt;

&lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/post/{id}'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'BlogController@getPost'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now let's open &lt;code&gt;app/Controllers/BlogController.php&lt;/code&gt; and add &lt;code&gt;getPost&lt;/code&gt; method to our class&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Controllers/BlogController.php&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'post'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now let's go to the browser and vist &lt;a href="http://localhost:8000/post/1"&gt;http://localhost:8000/post/1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This must be your result&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iWCDutJB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vqvepf5vhj9ndip66o9b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iWCDutJB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vqvepf5vhj9ndip66o9b.png" alt="Post"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Now let's edit
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;routes/web.php&lt;/code&gt;, let's add this route&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// routes/web.php&lt;/span&gt;

&lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/post/{id}/edit'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'BlogController@editPost'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;app/Controllers/BlogController.php&lt;/code&gt;, let's add the &lt;code&gt;editPost&lt;/code&gt; method to the &lt;code&gt;BlogController&lt;/code&gt; class but before that, let's first create a relation between the &lt;code&gt;Post&lt;/code&gt; model and &lt;code&gt;Comment&lt;/code&gt; model found in &lt;code&gt;app/Models&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;app/Models/Post.php&lt;/code&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Models/Post.php&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;hasMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Comment&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;app/Models/Comment.php&lt;/code&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Models/Comment.php&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;belongsTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;app/Controllers/BlogController.php&lt;/code&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Controllers/BlogController.php&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;editPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Let's create the comments from here&lt;/span&gt;
    &lt;span class="c1"&gt;// [`creator_name`, `post_id`, `comment_content`]&lt;/span&gt;
    &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Comment&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
        &lt;span class="s1"&gt;'creator_name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Hamid Semix'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'comment_content'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'This is the first comment'&lt;/span&gt;
    &lt;span class="p"&gt;]));&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Your comment has been saved"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now let's edit our &lt;code&gt;getPost&lt;/code&gt; method to incorporate comments to&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Controllers/BlogController.php&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'comments'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'post'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the editor&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K0FnOa8O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xzgesoa4vqs7cn57vo6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K0FnOa8O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xzgesoa4vqs7cn57vo6d.png" alt="Editor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This must be your result&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pMKZ6xg9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/i9879xywb4rqb5swr7yp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pMKZ6xg9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/i9879xywb4rqb5swr7yp.png" alt="Result"&gt;&lt;/a&gt;&lt;/p&gt;


</description>
      <category>php</category>
      <category>framework</category>
      <category>yugaframework</category>
      <category>yuga</category>
    </item>
    <item>
      <title>Foreign Function Interface for php</title>
      <dc:creator>Hamid Semix</dc:creator>
      <pubDate>Tue, 19 Feb 2019 10:44:50 +0000</pubDate>
      <link>https://dev.to/hsemix/foreign-function-interface-for-php-3nda</link>
      <guid>https://dev.to/hsemix/foreign-function-interface-for-php-3nda</guid>
      <description>&lt;p&gt;Is Foreign Function Interface really going to do much in the php world?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting started with yuga-framework part 2</title>
      <dc:creator>Hamid Semix</dc:creator>
      <pubDate>Fri, 08 Feb 2019 12:10:18 +0000</pubDate>
      <link>https://dev.to/hsemix/getting-started-with-yuga-framework-part-2-40b8</link>
      <guid>https://dev.to/hsemix/getting-started-with-yuga-framework-part-2-40b8</guid>
      <description>&lt;p&gt;In today's tutorial, I am going to take you through the steps required to build an actual blog application, I am sure you remember our first part was setting up an environmment.&lt;br&gt;
Let's first list down what we need to do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We need a database&lt;/li&gt;
&lt;li&gt;we need a posts table&lt;/li&gt;
&lt;li&gt;we need a comments table&lt;/li&gt;
&lt;li&gt;we need a form for submitting a post (will be covered in part 3)&lt;/li&gt;
&lt;li&gt;We need a page for displaying all posts (part 3)&lt;/li&gt;
&lt;li&gt;We need a mechanism of comment on a post (part 3)&lt;/li&gt;
&lt;li&gt;We need to save a post/comment (For now we will use a fairly raw approach)&lt;/li&gt;
&lt;li&gt;We need to query the database for posts and their comments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok, let's get this over with, shall we?&lt;/p&gt;
&lt;h2&gt;
  
  
  First we need to make a connection to a database
&lt;/h2&gt;

&lt;p&gt;Yuga comes with three database drivers integrated, the default one is mysql, to change the database to which our application connects, we will need to locate a file &lt;code&gt;(environment/.env)&lt;/code&gt;. This is the file that holds most of the framework's configurations. Let's name our database &lt;code&gt;blog&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdw08mpvvhnii4eqyu5xb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdw08mpvvhnii4eqyu5xb.png" alt="environment/.env"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Let's now create our tables in the database
&lt;/h2&gt;

&lt;p&gt;To create the blog tables, we will use yuga's command for migrations which is &lt;code&gt;php yuga migration:make&lt;/code&gt;.&lt;br&gt;
We will have two tables for now which are &lt;strong&gt;posts&lt;/strong&gt; and &lt;strong&gt;comments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open the project in the terminal and type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php yuga migration:make posts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do the same for comments, at this point, your database directory should like this&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxyzi2u7rxtb4kz8c5mt5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxyzi2u7rxtb4kz8c5mt5.png" alt="Migration Image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Let's run the command that creates these two tables
&lt;/h3&gt;

&lt;p&gt;Before we create our tables in the database we earlier created, we need to figure out which fields need to go to each of the tables i.e. posts and comments&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Posts table

&lt;ul&gt;
&lt;li&gt;id&lt;/li&gt;
&lt;li&gt;creator_name&lt;/li&gt;
&lt;li&gt;post_title&lt;/li&gt;
&lt;li&gt;post_content&lt;/li&gt;
&lt;li&gt;created_at&lt;/li&gt;
&lt;li&gt;updated_at&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Comments table

&lt;ul&gt;
&lt;li&gt;id&lt;/li&gt;
&lt;li&gt;creator_name,&lt;/li&gt;
&lt;li&gt;post_id&lt;/li&gt;
&lt;li&gt;comment_content&lt;/li&gt;
&lt;li&gt;created_at&lt;/li&gt;
&lt;li&gt;updated_at&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's put these fields with their appropriate data types in the migrations we just created&lt;/p&gt;

&lt;p&gt;Now, In your terminal, enter this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php yuga migration:up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will create the tables and now we should have the following&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4cnrk27fs747ofqnsj8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4cnrk27fs747ofqnsj8g.png" alt="Migration done"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Models for posts table and comments table
&lt;/h2&gt;

&lt;p&gt;Now that we have our tables created, we need a way we can communicate with them in a flawless way, Luckly for us, yuga comes with an &lt;strong&gt;ORM&lt;/strong&gt; for database manipulation, so let's create the Post model and the Comment model.&lt;br&gt;
NB: Because our tables are &lt;strong&gt;posts&lt;/strong&gt; and &lt;strong&gt;comments&lt;/strong&gt;, this explains while our Models will be &lt;strong&gt;Post&lt;/strong&gt; and &lt;strong&gt;Comment&lt;/strong&gt; respectively as yuga converts the class name of the model and &lt;strong&gt;pluralizes&lt;/strong&gt; and &lt;strong&gt;lowercases&lt;/strong&gt; it, that's what it takes as the table (But customisable).&lt;/p&gt;

&lt;p&gt;That's what we will use to &lt;strong&gt;save&lt;/strong&gt; and &lt;strong&gt;retrieve&lt;/strong&gt; data from the tables (&lt;strong&gt;models&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;Let's use the yuga commands again for this task,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php yuga make:model Post

php yuga make:model Comment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdzglebkhvhs243fe5q9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdzglebkhvhs243fe5q9c.png" alt="Model"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Save data in our post table
&lt;/h2&gt;

&lt;p&gt;To interact with our tables, we need a route which in the end calls a controller on our behalf. It's in the controller that we write our logic for saving our post to a database.&lt;br&gt;
To create a controller we use &lt;code&gt;php yuga make:controller BlogController&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Let's open the created controller and create a method called &lt;code&gt;createPost&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now let's open &lt;code&gt;routes/web.php&lt;/code&gt; file to create our route. This file has one route which is &lt;code&gt;/&lt;/code&gt;, now let's add another route &lt;code&gt;/post/create&lt;/code&gt; which we will use to create our blog post.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// routes/web.php&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/post/create'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'BlogController@createPost'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhkwy5aa8e7p71e0xjlus.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhkwy5aa8e7p71e0xjlus.png" alt="Controller Route"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the controller&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Controllers/BlogController.php&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;createPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Post&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
        &lt;span class="s1"&gt;'creator_name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Jone Doe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'post_title'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'I believe every human has a finite number of heartbeats. I don\'t intend to waste any of mine.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'post_content'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Never in all their history have men been able truly to conceive of the world as one: a single sphere, a globe, having the qualities of a globe, a round earth in which all the directions eventually meet, in which there is no center because every point, or none, is center — an equal earth which all men occupy as equals. The airman\'s earth, if free men make it, will be truly round: a globe in practice, not in theory.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Your Post has been saved'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You must have the following result when you vist &lt;a href="http://localhost:8000/post/create" rel="noopener noreferrer"&gt;http://localhost:8000/post/create&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy8rixr7gpicnbpdov5ds.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy8rixr7gpicnbpdov5ds.png" alt="Result"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>framework</category>
      <category>yugaframework</category>
      <category>yuga</category>
    </item>
    <item>
      <title>Getting started with the yuga-framework part 1</title>
      <dc:creator>Hamid Semix</dc:creator>
      <pubDate>Tue, 05 Feb 2019 12:45:40 +0000</pubDate>
      <link>https://dev.to/hsemix/getting-started-with-the-yuga-framework-f80</link>
      <guid>https://dev.to/hsemix/getting-started-with-the-yuga-framework-f80</guid>
      <description>&lt;p&gt;There is a full list of frameworks most of which are php frameworks, these frameworks help in Rapid Application &lt;br&gt;
Development. However, some of these frameworks are really had to get started with, have complex paradigms, &lt;br&gt;
and some are not good enough for an advanced php developer. This is where the yuga-framework comes in handy.&lt;/p&gt;

&lt;p&gt;In this tutorial, I will introduce you to yuga-framework a framework for PHP that leverages between a beginner and advanced developer. Yuga-framework can be used just to develop apis or fully fledged web applications.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Yuga-framework?
&lt;/h2&gt;

&lt;p&gt;Yuga is a php framework that is ideal for rapid web app development, It can be used to develop apis or an entire web application like mentioned earlier. It supports all HTTP verbs or methods (GET, POST, PUT, DELETE, PATCH, and custom ones). It has automatic form validation, automatic cross site request forgery protection on routes and does not force the user to use Route methods if they aren't coming from that background. You can learn and advance with the framework.&lt;/p&gt;
&lt;h3&gt;
  
  
  Steps needed to get started with yuga-framework
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Step 1: Install Composer
&lt;/h4&gt;

&lt;p&gt;Install composer (php package manager) if you don't already have it on your machine from &lt;a href="https://getcomposer.org/download/"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 2: Install Yuga Framework From Packagist using composer
&lt;/h4&gt;

&lt;p&gt;To get started you just need one command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer create-project yuga/yuga Blog
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Run the application
&lt;/h4&gt;

&lt;p&gt;To run the application we have just created using composer, we &lt;strong&gt;cd&lt;/strong&gt; to &lt;em&gt;Blog&lt;/em&gt; and open the project in terminal or console, type the following &lt;strong&gt;yuga command&lt;/strong&gt;, Oooh, Did I forget to mention that the framework comes with its own console application, I just did.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php yuga start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 4: See output
&lt;/h4&gt;

&lt;p&gt;To see what the yuga start command has done, go to your browser and visit &lt;a href="http://localhost:8000"&gt;http://localhost:8000&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step Finale
&lt;/h4&gt;

&lt;p&gt;Open the project in your favorite editor, in my case it's vs code. Let's try to see the file structure&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;app

&lt;ul&gt;
&lt;li&gt;Controllers&lt;/li&gt;
&lt;li&gt;helpers (optional)&lt;/li&gt;
&lt;li&gt;Middleware (created automatically when you make a middleware using a yuga command).&lt;/li&gt;
&lt;li&gt;Models&lt;/li&gt;
&lt;li&gt;Providers (houses your application service providers)&lt;/li&gt;
&lt;li&gt;ViewModels (Where view models live). The framework is well integrated with ViewModels so that's where our logic will reside&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;boot (framework specific) do not touch&lt;/li&gt;
&lt;li&gt;config (Where the configuration settings of you application reside). Feel free to alter and see how the application changes&lt;/li&gt;
&lt;li&gt;database (Where migrations live)&lt;/li&gt;
&lt;li&gt;environment (Where environment settings live)&lt;/li&gt;
&lt;li&gt;mailables (Where files that can be sent as emails reside). This can change&lt;/li&gt;
&lt;li&gt;public (Where you should point your server instance)&lt;/li&gt;
&lt;li&gt;resouces (Where views are saved)&lt;/li&gt;
&lt;li&gt;routes

&lt;ul&gt;
&lt;li&gt;web.php (A file that holds all our routes)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;storage&lt;/li&gt;
&lt;li&gt;tests&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>php</category>
      <category>framework</category>
      <category>yugaframework</category>
      <category>yuga</category>
    </item>
  </channel>
</rss>
