tag:blogger.com,1999:blog-34511079193194701982024-02-07T14:45:10.282-08:00THE COMPUTER LOVERS #1 In Tutorials, News, Videos And Hot Updates On >>>
HTML || JAVA || C,C++,C# || WEB DESIGN || PROGRAMMING || SCRIPTING || TUTORIALS
Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.comBlogger64125tag:blogger.com,1999:blog-3451107919319470198.post-91446503635877322822020-12-03T02:25:00.001-08:002020-12-03T02:26:34.086-08:00Laravel one to one relationship with example<p> </p><h1 class="title" style="background-color: white; border: none; box-sizing: border-box; color: #212529; font-family: Poppins, sans-serif; font-size: 2rem; font-weight: 500; line-height: 1.125; margin: 0px 0px 0.5rem; outline: none; word-spacing: 1px;">Laravel one to one relationship with example</h1><article class="card-text" style="background-color: white; border: none; box-sizing: border-box; color: #222222; font-family: Merriweather, roboto; font-size: 1.125rem; line-height: 1.8; margin: 2rem 0px 0px; outline: none; word-spacing: 1px;"><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">“Laravel eloquent one to one relationship with example”: A one-to-one relationship is a very basic, fundamental Laravel eloquent relationship.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Following our <a href="https://masteringbackend.com/posts/complete-guide-on-laravel-relationships" style="background-color: transparent; border: none; box-sizing: border-box; color: #bd4147; cursor: pointer !important; margin: 0px; outline: none; text-decoration-line: none;">complete guide to Laravel relationships</a>, it simply relates one entity to another.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">For instance, in our voting application, a User is associated with one Vote.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">If we were to describe this relationship, we could say:</p><blockquote class="wp-block-quote" style="border: none; box-sizing: border-box; margin: 0px 0px 1rem; outline: none;"><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">“<em style="border: none; box-sizing: border-box; margin: 0px; outline: none;">Each user has one vote”.</em></p></blockquote><p><a href="https://masteringbackend.com/posts/laravel-one-to-one-relationship-with-example">READ THE UPDATED VERSION HERE</a> </p><h2 style="border: none; box-sizing: border-box; font-size: 1.5rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">Defining a one-to-one relationship</h2><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In order to define this relationship, we call the <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">hasOne</span></code> method on the entity that owns the relationship.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Here’s a code snippet defining the relationship.</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">namespace</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Database</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Eloquent</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">User</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">extends</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>
</span>{
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">/**
* Get's this user's vote
*/</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">vote</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span>
</span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">$this</span>->hasOne(App\Models\Vote::class);
}
}</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">What happens here is, we pass the name of the related model (the <code class="hljs coffeescript" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;">::<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span></span></code> property returns the full name of the class).</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Once we’ve defined this relationship, we can always easily get the vote associated with any user in our database using Eloquent’s dynamic properties.</p><h3 style="border: none; box-sizing: border-box; font-size: 1.75rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">Querying one-to-one Relationship</h3><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Eloquent’s dynamic properties allow us to query relationships and get the values as if they are properties defined on the object. </p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">We could do something like this:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">namespace</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Http</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Controllers</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">User</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">RandomController</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">extends</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Controller</span> </span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">getUserVote</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span></span>{
$user = User::find(<span class="hljs-number" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">1</span>); <span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Get a User Instance</span>
$vote = $user->vote; <span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Get the Vote that this User has</span>
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Do whatever with it</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> response([<span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'vote'</span> => $vote], <span class="hljs-number" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">200</span>);
}
}</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">As you can see we can get this user’s vote as if it were a property of this user object.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">What actually happens under the hood by default is:</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">When we access the vote property, Eloquent makes a database query to the votes table using the foreign key that points to the current user’s primary key on the user’s table.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">That’s why it’s called a dynamic property<em style="border: none; box-sizing: border-box; margin: 0px; outline: none;">; </em>because its values are not predefined, rather it’s gotten on the fly by a database call.</p><h4 style="border: none; box-sizing: border-box; font-size: 1.5rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">Laravel Naming</h4><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Now you may ask?</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">How does Eloquent know the correct name of the primary/local key on the user’s table?</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">And how does it know where to get that key (the foreign key) on the votes table?</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Well, let’s answer these questions. </p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">First of all, the primary key of Laravel tables is called <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">ID</span></code>. It is possible to change this in<a href="https://laravel.com/docs/8.x/eloquent#eloquent-model-conventions" rel="noreferrer noopener" style="background-color: transparent; border: none; box-sizing: border-box; color: #bd4147; cursor: pointer !important; margin: 0px; outline: none; text-decoration-line: none;" target="_blank"> the Model class</a>.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Laravel uses this primary key as the local key.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Eloquent also has a convention for naming the foreign key on the votes table: we always append <code class="hljs objectivec" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;">_<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">id</span></code> to the name of the model that owns the relationship.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In our example, the votes table would have a column called <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">user_id</span></code>. This <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">user_id</span></code> would always point to the <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">ID</span></code> of the user that owns that vote.</p><figure class="wp-block-image size-large" style="border: none; box-sizing: border-box; margin: 0px 0px 1rem; outline: none;"><img alt="gzBpXNOv 1024x651 - Laravel one to one relationship with example" class="wp-image-120" height="651" loading="lazy" sizes="(max-width: 1024px) 100vw, 1024px" src="https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/11/gzBpXNOv-1024x651.png" srcset="https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/11/gzBpXNOv-1024x651.png 1024w, https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/11/gzBpXNOv-300x191.png 300w, https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/11/gzBpXNOv-768x488.png 768w, https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/11/gzBpXNOv-1536x976.png 1536w, https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/11/gzBpXNOv.png 1600w" style="background-size: cover; border: none; box-sizing: border-box; height: auto; margin: 0px; max-width: 100%; outline: none; vertical-align: middle; width: 1005.98px;" title="Laravel one to one relationship with example" width="1024" /></figure><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">You may also think at this point:</p><h4 style="border: none; box-sizing: border-box; font-size: 1.5rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">Laravel Custom Keys</h4><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">This is fun and all, but what if I don’t want to use this convention? Or what if I have a different column I want to use as the foreign key or local key?</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Eloquent provides a convention for this too, and it’s like this:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">namespace</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Database</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Eloquent</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">User</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">extends</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>
</span>{
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">/**
* Get's this user's vote
*/</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">vote</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span>
</span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">$this</span>->hasOne(App\Models\Vote::class, <span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'foreign_key'</span>, <span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'local_key'</span>);
}
}</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Looking at the snippet, we see that the <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">hasOne</span></code> method can accept up to three parameters.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">The first parameter is required, and it provides the full name of the Eloquent model that forms the relationship. </p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">The second argument is optional, and it specifies the name of the foreign key.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">The foreign key is the column that Eloquent checks for when we call the dynamic property.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">What this means is if we actually wrote this method, Eloquent would look for the vote by checking for the column <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">foreign_key</span></code> on the votes, table to see if the value is the same on the <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">local_key</span></code> column of the user’s table.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;"><em style="border: none; box-sizing: border-box; margin: 0px; outline: none;">Did you get it? Please read it again if you didn’t.</em></p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;"><br style="border: none; box-sizing: border-box; margin: 0px; outline: none;" />The third argument is optional, and it defines the local key on the entity that has the relationship.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">So in our snippet, if we didn’t put the third argument to be <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">local_key</span></code>, whenever Eloquent is checking for votes, it would check the default <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">ID</span></code> column.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;"><span style="border: none; box-sizing: border-box; font-weight: bolder; margin: 0px; outline: none;">Note:</span> If you want to omit the second argument, but provide a value for the third one, simply put null as the second argument, meaning your code will look like this: </p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs kotlin" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> $<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">this</span>->hasOne(App\Models\Vote::<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span>, <span class="hljs-type" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">null</span>, <span class="hljs-type" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">'local_key);</span></span></code></pre><div class="newsletter-laravel" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"></div><h2 style="border: none; box-sizing: border-box; font-size: 1.5rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">Defining the Inverse of One to One Relationships</h2><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In Laravel “one to one relationship” with an example, defining an inverse relationship is also made very easy and straightforward.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Well, it’s fun to find the vote of each user.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">But what if we had a vote and we wanted to find the user that vote belongs to?</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Eloquent provides a convenient means of defining the inverse of One-to-One relationships. </p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">If we want to define the relationship that states: <em style="border: none; box-sizing: border-box; margin: 0px; outline: none;">“Each vote belongs to a user</em>”, we use the <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">belongsTo</span></code> method like this:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">namespace</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Database</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Eloquent</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Vote</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">extends</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span> </span>{
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">/**
* Get's this vote's owner
*/</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">user</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span> </span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">$this</span>->belongsTo(App\Models\User::class);
}
}</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Once this is defined, we can get our user just like we showed earlier by using the dynamic property.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">We would be able to call the user property on a vote instance as it existed.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In a similar fashion, Eloquent would run a database query behind the scenes that checks for the <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">user_id</span></code> column on the votes table and see if it matches a record with the same <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">ID</span></code> on the user’s table. </p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">If you don’t want this convention, you can also define different foreign and local keys like we did above.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">So this snippet would look like this:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;">
<span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">namespace</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Database</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Eloquent</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Vote</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">extends</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span> </span>{
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">/**
* Get's this vote's user
*/</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">user</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span> </span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">$this</span>->belongsTo(App\Models\User::class, <span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'foreign_key'</span>, <span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'local_key'</span>);
}
}</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Just as explained earlier, with this we can set the foreign key (on the user’s table ) or the local key (on the vote’s table) to a different column by using the optional second and third parameters of the <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">belongsTo</span></code> method.</p><h2 style="border: none; box-sizing: border-box; font-size: 1.5rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">Retrieving a One to One Relationship</h2><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Once we’ve defined our relationship, it’s easy to get the values and start having fun with it.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">To get the value of the relationship, we simply use the dynamic property to get it.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">So, if we wanted to get our vote given a user, we would do:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs php" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">User</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">RandomClass</span> </span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">randomFunction</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span></span>{
$user = User::find(<span class="hljs-number" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">1</span>); <span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Gets a User Instance</span>
$vote = $user->vote; <span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Gets the User's Vote</span>
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Do whatever with it</span>
print_r($vote);
}
}</code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In addition to using dynamic properties to get the values of relationships, you can go further down the relationship to get the relationship of your relationship.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">So if we wanted to get the party our user voted for, and we already defined Laravel One-to-One relationships between <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">Vote</span></code> and <code class="hljs ebnf" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">PoliticalParty</span></code> models, we can do this:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">User</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">RandomClass</span> </span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">randomFunction</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span></span>{
$user = User::find(<span class="hljs-number" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">1</span>); <span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Gets a User Instance</span>
$vote = $user->vote->politicalParty; <span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Gets the party the user voted for</span>
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Do whatever with it</span>
print_r($vote);
}
}</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">You can get an in-depth article on “<a href="https://masteringbackend.com/posts/laravel-one-to-one-relationship-with-example#" style="background-color: transparent; border: none; box-sizing: border-box; color: #bd4147; cursor: pointer !important; margin: 0px; outline: none; text-decoration-line: none;">Laravel one to many relationships with example</a>” that explain everything from creating the relationship, the inverse method of creating it, and how to retrieve the data.</p><h2 style="border: none; box-sizing: border-box; font-size: 1.5rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">Getting Started with Laravel One to One CRUD Example (Word Matching Game)</h2><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In order to better illustrate one-to-one relationships, we’ve prepared a repository you can clone that shows one-to-one relationships in action.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In this repository, we build a simple game where you pick the best word or words from the select box on the right that matches the word on the left.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Feel free to<a href="https://github.com/EricMcWinNer/laravel-one-to-one" rel="noreferrer noopener" style="background-color: transparent; border: none; box-sizing: border-box; color: #bd4147; cursor: pointer !important; margin: 0px; outline: none; text-decoration-line: none;" target="_blank"> clone the repository</a> so we can get started.</p><figure class="wp-block-image size-large" style="border: none; box-sizing: border-box; margin: 0px 0px 1rem; outline: none;"><img alt="Jjq40xTI 1024x798 - Laravel one to one relationship with example" class="wp-image-184" height="798" loading="lazy" sizes="(max-width: 1024px) 100vw, 1024px" src="https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/12/Jjq40xTI-1024x798.png" srcset="https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/12/Jjq40xTI-1024x798.png 1024w, https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/12/Jjq40xTI-300x234.png 300w, https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/12/Jjq40xTI-768x598.png 768w, https://masteringbackend.solomoneseme.com/wp-content/uploads/2020/12/Jjq40xTI.png 1099w" style="background-size: cover; border: none; box-sizing: border-box; height: auto; margin: 0px; max-width: 100%; outline: none; vertical-align: middle; width: 1005.98px;" title="Laravel one to one relationship with example" width="1024" /></figure><div class="newsletter-laravel" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"></div><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In order to run the application, you’d have install composer dependencies with:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs cmake" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;">composer <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">install</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Then you’d have to run the migrations (after creating a database and setting credentials in your <code class="hljs asciidoc" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;"><span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">.env</span></code> file of course:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs ebnf" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="hljs-attribute" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">php artisan migrate</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Finally, we’d have to seed the database:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs css" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="hljs-selector-tag" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">php</span> <span class="hljs-selector-tag" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">artisan</span> <span class="hljs-selector-tag" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">db</span><span class="hljs-selector-pseudo" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">:seed</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">The application stores two entities, Word and Match and they have a One to One relationship.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Every word has a match, and every match belongs to a word.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">We define this relationship in <code class="hljs reasonml" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;">app/Models/<span class="hljs-module-access" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-identifier" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">Word</span>.</span>php</code> and <code class="hljs reasonml" style="background: rgb(40, 42, 54); border-radius: 0.25rem; border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 16.2px; font-style: italic; margin: 0px; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em;">app/Models/<span class="hljs-module-access" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-identifier" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">Match</span>.</span>php</code> respectively:</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// app/Models/Word.php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">namespace</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Database</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Eloquent</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Factories</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">HasFactory</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Database</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Eloquent</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Word</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">extends</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>
</span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">HasFactory</span>;
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Define the One to One Relationship</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">match</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span> </span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">$this</span>->hasOne(Match::class);
}
}</span></code></pre><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// app/Models/Word.php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">namespace</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Database</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Eloquent</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Factories</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">HasFactory</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Database</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Eloquent</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Match</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">extends</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Model</span>
</span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">HasFactory</span>;
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Define the inverse of the relationship</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">word</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">()</span>
</span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">$this</span>->belongsTo(Word::class);
}
}</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Finally, we use the relationship in the controller that the homepage’s form submits to, we use the inverse relationship to loop through the submitted values and increment the score (we could have used the default relationship too).</p><pre class="wp-block-code" style="border: none; box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 15.75px; margin-bottom: 1rem; margin-top: 0px; outline: none; overflow: auto;"><code class="hljs xml" style="background: rgb(40, 42, 54); border: none; box-sizing: border-box; color: #f8f8f2; display: block; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; margin-bottom: 1rem !important; margin-left: 0px; margin-right: 0px; margin-top: 1rem; outline: none; overflow-wrap: break-word; overflow-x: auto; padding: 0.5em; word-break: normal;"><span class="php" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-meta" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;"><?php</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">namespace</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Http</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Controllers</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Match</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">App</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Models</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Word</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">use</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Illuminate</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Http</span>\<span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Request</span>;
<span class="hljs-class" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">class</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">WordMatcher</span> <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">extends</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">Controller</span>
</span>{
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">public</span> <span class="hljs-function" style="border: none; box-sizing: border-box; margin: 0px; outline: none;"><span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #ff79c6; font-weight: 700; margin: 0px; outline: none;">function</span> <span class="hljs-title" style="border: none; box-sizing: border-box; color: #f1fa8c; font-weight: 700; margin: 0px; outline: none;">submit</span><span class="hljs-params" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">(Request $request)</span>
</span>{
$matches = $request->input(<span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'match'</span>);
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Gets all words as a collection in the same order they are shown on the page</span>
$words = Word::orderBy(<span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'value'</span>, <span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'asc'</span>)->get();
$total = $words->count();
$score = <span class="hljs-number" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">0</span>;
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">foreach</span> ($matches <span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">as</span> $key => $match) {
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// Loop through the submitted words and use the inverse relationship to check if they are related.</span>
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">if</span> (Match::find($match)->word->id === $words[$key]->id)
$score += <span class="hljs-number" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">1</span>;
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// The check could also be achieved by using the actual One to One relationship like this:</span>
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// if($words[$key]->match->id == $match)</span>
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">// $score += 1;</span>
<span class="hljs-comment" style="border: none; box-sizing: border-box; color: #6272a4; margin: 0px; outline: none;">/******************************
*
* N.B
*
* Using strict equality (===) in the commented if statemen with the actual relationship
* won't work because $match is a string while -> id returns an integer,
* and the types are not the same
*
*****************************/</span>
}
$percent = floor(($score / $total) * <span class="hljs-number" style="border: none; box-sizing: border-box; margin: 0px; outline: none;">100</span>);
session()->flash(<span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">"score_status"</span>, <span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">"success"</span>);
session()->flash(<span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">"score_status_title"</span>, <span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">"Here's your Score"</span>);
session()->flash(<span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">'score_status_message'</span>, <span class="hljs-string" style="border: none; box-sizing: border-box; color: #f1fa8c; margin: 0px; outline: none;">"You got $percent% and matched $score out of $total words correctly."</span>);
<span class="hljs-keyword" style="border: none; box-sizing: border-box; color: #8be9fd; font-weight: 700; margin: 0px; outline: none;">return</span> back();
}
}</span></code></pre><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">The rest of the code in the repository are frontend code, and the code to render the words and matches on the frontend.</p><h2 style="border: none; box-sizing: border-box; font-size: 1.5rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">What’s Next?</h2><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">You can get an in-depth article on “<a href="https://masteringbackend.solomoneseme.com/wp-admin/post.php?post=117&action=edit#" style="background-color: transparent; border: none; box-sizing: border-box; color: #bd4147; cursor: pointer !important; margin: 0px; outline: none; text-decoration-line: none;">Laravel one to many relationships with example</a>” that explain everything from creating the relationship, the inverse method of creating it, and how to retrieve the data.</p><h2 style="border: none; box-sizing: border-box; font-size: 1.5rem; font-weight: 500; line-height: 1.2; margin: 0px 0px 0.5rem; outline: none; padding-bottom: 0.8rem; padding-top: 0.8rem;">Conclusion</h2><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">In this article, we had an in-depth look at Laravel’s “One to One relationships”, as well as an application implementing the relationship to solve a problem.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">One to One relationships are basic and help in writing applications in a more fluent way. </p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Feel free to check out our other articles where we similarly go in-depth to explain other <a href="https://masteringbackend.solomoneseme.com/posts/complete-guide-on-laravel-relationships/" style="background-color: transparent; border: none; box-sizing: border-box; color: #bd4147; cursor: pointer !important; margin: 0px; outline: none; text-decoration-line: none;">Laravel relationships</a>.</p><p style="border: none; box-sizing: border-box; margin: 0px 0px 2rem; outline: none;">Feel free to let us know if you have any questions and we’d love to help.</p></article><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com1tag:blogger.com,1999:blog-3451107919319470198.post-67630765191949898252019-08-20T04:31:00.001-07:002019-08-20T04:36:39.325-07:00My Love For Canada<div dir="ltr" style="text-align: left;" trbidi="on">
<span id="docs-internal-guid-5ab4fff2-7fff-f31b-5d92-2a40f2a6ab2c"><span style="font-family: "arial"; font-size: 11pt; vertical-align: baseline; white-space: pre-wrap;">It seems like these days, many people love this country of my first love, Canada, i have always dreamt of being in it as a full fledged citizen having the right to do anything as stated by the law for every citizen, I have my reasons for such love but you can simply take a deep dive into discovering more about the country and why I have such a strong love for this country <a href="http://timbu.com/canada">here</a>. <a href="https://www.timbu.com/canada">timbu.com/canada</a></span></span></div>
<div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com2tag:blogger.com,1999:blog-3451107919319470198.post-89768614771039334322019-01-12T10:08:00.001-08:002019-01-12T10:08:10.331-08:00Create a nigerian news blog -4- Homepage Customization Finalized<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/cW69gw7UrJQ" width="480"></iframe><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com2tag:blogger.com,1999:blog-3451107919319470198.post-77022897259471016932018-12-14T03:54:00.002-08:002020-11-23T02:56:07.661-08:0012 Productive Tips for Backend DevelopersHey guys, i just drop a new video on my 12 productive tips as a <a href="https://masteringbackend.com/posts/getting-started-with-backend-development" target="_blank">backend developer</a>. I want to hear your honest thoughts on this subject to assist others improve productivity. Thanks<div><br /></div><div>Read more of my <a href="https://masteringbackend.com/posts/12-productive-tips-for-backend-developers" target="_blank">12 productive tips for backend developers</a><br /><br /><br />
<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/4t7-nQafQFo" width="480"></iframe><br /><br />
<br /></div><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-89894730924220797232018-10-20T22:29:00.001-07:002018-10-20T22:29:41.393-07:00Make Jaguda Website - 6 - Installing the ThemeHow to create a music website step by step.<br /><br />
In this tutorial our example website is jaguda website.<br /><br />
<br /><br />
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/6MpRGmCLZnA" width="480"></iframe><br /><br />
<br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-32792245784679008252018-10-06T13:44:00.001-07:002018-10-06T14:03:40.830-07:00Make Jaguda Website - 4 - Overview of wordpress<div dir="ltr" style="text-align: left;" trbidi="on">
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/3DJmlGlAagk" width="480"></iframe></div>
<div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-7677983957471840232017-08-08T02:22:00.001-07:002017-08-08T02:22:21.033-07:00Java Login Tutorial Using MySQL, Access And SQLite - 1 - Creating the Lo...<iframe allowfullscreen="" frameborder="0" height="344" src="https://www.youtube.com/embed/5XZJwVHqUXQ" width="459"></iframe><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-15082702187449439452017-08-02T09:06:00.001-07:002017-08-02T09:06:26.926-07:00Make a music website like tooXclusive - 7 - Configuring the homepage<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/VQzwzarwQpI" width="480"></iframe><br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-13820513341753005202017-06-20T06:44:00.001-07:002017-06-20T06:44:33.623-07:00Latest Cover: FALL BY #DAVIDO Mark Angel Comedy with Emmanuella<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/eqMhS3XFjZE" width="480"></iframe><br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-52135451737722701632017-05-12T03:30:00.001-07:002017-05-12T03:30:16.683-07:00NEW EPISODE: SHE WAS THERE Mark Angel Comedy Episode 113<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/P3RPaDuFr1M" width="480"></iframe><br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-9862618333116568932017-04-27T06:43:00.003-07:002017-04-27T06:43:42.686-07:00HOW TO CREATE A WEBSITE LIKE NAIJALOADED<iframe allowfullscreen="" frameborder="0" height="344" src="https://www.youtube.com/embed/videoseries?list=PLJNW2DKDGQpmG5DTicR7tTtgzRYa1rdJn" width="425"></iframe><br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-49545223121341060342017-04-27T06:43:00.001-07:002017-04-27T06:43:13.102-07:00How To Create A Music Site Like TooXclusive<iframe allowfullscreen="" frameborder="0" height="344" src="https://www.youtube.com/embed/videoseries?list=PLJNW2DKDGQpmeaNg1mLcM0P_3S-9tY2EK" width="425"></iframe><br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-10241792678603016452017-04-27T06:41:00.001-07:002017-04-27T06:41:21.224-07:00Create Professional Login Window In Java Using MySQL, Access, SQLite<iframe allowfullscreen="" frameborder="0" height="344" src="https://www.youtube.com/embed/videoseries?list=PLJNW2DKDGQplIpgZQl_3DPkqhLsg4gxuf" width="425"></iframe><br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-11686172876764630172016-10-27T23:34:00.001-07:002016-10-27T23:34:06.566-07:00Create Professional Login Window In Java Using MySQL, Access, SQLite<iframe allowfullscreen="" frameborder="0" height="344" src="https://www.youtube.com/embed/videoseries?list=PLJNW2DKDGQplIpgZQl_3DPkqhLsg4gxuf" width="425"></iframe><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-64053864193209035212016-09-27T17:32:00.001-07:002016-09-27T17:32:29.472-07:00Create Professional Login Window In Java Using MySQL, Access, SQLite<iframe allowfullscreen="" frameborder="0" height="344" src="https://www.youtube.com/embed/videoseries?list=PLJNW2DKDGQplIpgZQl_3DPkqhLsg4gxuf" width="425"></iframe><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-41628890988941237162016-09-22T16:56:00.000-07:002016-09-22T16:56:21.736-07:00Top 9 Things A Church Website Should Have<div dir="ltr" style="text-align: left;" trbidi="on">
A church website is a pretty big responsibility. Thankfully, it’s not impossible to keep up with the responsibility. It just requires a clear head about a few things. Here, we’ve collected a list of NINE things that your church website should absolutely have. After several years of making church websites.<br /><br />Here is what your church website should have:<br /><br /> A DESIGN THAT REFLECTS “PEOPLE”, NOT BUILDINGS. People are searching for others whom they can relate to in order to establish a relationship. Buildings represent “institution”, not one on one fellowship.<br /><br /> ANNOUNCEMENTS AND CALENDAR OF EVENTS. The page that gets the most visits on any church site is the events page. Surveys on many church websites have revealed as high as 60% of visitors are looking for information about what, where, and when. A website can be a cost saving advertisement medium.<br /><br /> A WAY FOR PEOPLE TO FIND OUT HOW TO GET INVOLVED. This is for someone who is new to your church and really wants to get plugged in. All churches need volunteers, but most do not have an easy way for someone to learn about the need, or how and who to contact to get involved.<br /><br /> A WAY FOR USERS TO REGISTER ONLINE. Whether it’s just registering for a newsletter, registering for events, or having an entire section of your site for registered users, you need to get people to tell you who they are. A good website program will have this option as a standard.<br />
<a name='more'></a><br /><br /> A WAY FOR USERS TO CONTACT YOU FROM THE WEBSITE. A simple email link will not do. You need to provide as much contact information as possible, including address, phone, email address, and an online form so site visitors can submit an email directly from the website. Directions, service times, and office schedule. It’s easy to provide a link from Map quest, but much more<br /><br /> A WELL KEPT “RESOURCE DOWNLOAD” AREA. Whether it’s a download area for bulletins, sermon notes, or audio and video downloads, you need something to keep people coming back. Think “Web Ministry”!<br /><br /> READ MORE http://cs-school.com/things-a-church-website-should-have/<br /></div>
<div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-31675007239636604092016-09-08T19:23:00.001-07:002016-09-08T19:23:17.244-07:00How to create a music website like tooXclusive - 8 - Setting up the Menu<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/sHH28W1Ur-A" width="480"></iframe><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-26949274606750410282016-08-28T15:56:00.001-07:002016-08-28T15:56:51.751-07:00How to create a music website like tooXclusive - 7 -Configuring the home...<br /><br />
<br /><br />
How to create a music website like tooXclusive - 7 -Configuring the homepage<br />Alright Guys, in this Video series i taught you quys how to create a music website like tooxclusive with simple steps...<br />OUR YOUTUBE CHANNEL - www.youtube.com/c/multimegaitschool<br />CHECK IT OUT AND DONT FORGET TO SUBSCRIBE...<br />USE OUR COMMENT BOX.<br />//====================================================<br />Project Materials► https://cs-school.com/<br />Twitter ► http://www.twitter.com/kaperskyguru<br />Website ► http://www.cs-school.com<br />Facebook ► http://www.facebook.com/multimegaitschool<br />Want more? You can join thousand of members to discover more about computer science, technology, programming.. visit: http://www.cs-school.com<br />————————————————————————————————-<br />Website: http://www.cs-school.com<br />Twitter: http://www.twitter.com/kaperskyguru<br />Facebook: http://www.facebook.com/multimegaitschool<br />Chat, Forum, Group: http://www.cs-school.com/forums <div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-43718987877978219522016-08-18T06:28:00.001-07:002016-08-18T06:28:17.224-07:00How to create a music website like tooXclusive -4-Adding Widget<br /><br />
<br /><br />
Hey guys i just updated my list on HOW TO CREATE A WEBSITE LIKE TOOXCLUSIVE ... CHECK IT OUT <br /><br />
<brr><br />
</brr><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-62570959074674267912016-08-11T08:08:00.001-07:002016-08-11T08:08:11.512-07:00How to create a music website like tooXclusive 2 Setting Up the Enviro...<br /><br />
<br /><br />
LEARN HOW TO CREATE A MUSIC WEBSITE LIKE TOOXCLUSIVE .2. Setting Up the Environment<br /><br />Alright Guys, in this Video series i taught you quys how to create a music website like tooxclusive with simple steps... <br /><br />OUR YOUTUBE CHANNEL - www.youtube.com/c/multimegaitschool<br /><br />CHECK IT OUT AND DONT FORGET TO SUBSCRIBE...<br /><br />USE OUR COMMENT BOX.<br /><br />//====================================================<br /><br />Project Materials► https://cs-school.com/<br /><br />Twitter ► http://www.twitter.com/kaperskyguru<br />Website ► http://www.cs-school.com<br />Facebook ► http://www.facebook.com/multimegaitsc...<br /><br />Want more? You can join thousand of members to discover more about computer science, technology, programming.. visit: http://www.cs-school.com<br /><br />————————————————————————————————-<br /><br />Website: http://www.cs-school.com<br />Twitter: http://www.twitter.com/kaperskyguru<br />Facebook: http://www.facebook.com/multimegaitsc...<br />Chat, Forum, Group: http://www.cs-school.com/forums <br /><br />
<br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-67453352979188288942016-08-10T06:43:00.001-07:002016-08-10T06:43:41.626-07:00How to create a music website like tooXclusive 1 Introduction<br /><br />
<br /><br />
LEARN HOW TO CREATE A MUSIC WEBSITE LIKE TOOXCLUSIVE .1. INTRODUCTION<br /><br />Alright Guys, in this Video series i taught you quys how to create a music website like tooxclusive with simple steps... <br /><br />OUR YOUTUBE CHANNEL - www.youtube.com/c/multimegaitschool<br /><br />CHECK IT OUT AND DONT FORGET TO SUBSCRIBE...<br /><br />USE OUR COMMENT BOX.<br /><br />//====================================================<br /><br />Project Materials► https://cs-school.com/<br /><br />Twitter ► http://www.twitter.com/kaperskyguru<br />Website ► http://www.cs-school.com<br />Facebook ► http://www.facebook.com/multimegaitschool<br /><br />Want more? You can join thousand of members to discover more about computer science, technology, programming.. visit: http://www.cs-school.com<br /><br />————————————————————————————————-<br /><br />Website: http://www.cs-school.com<br />Twitter: http://www.twitter.com/kaperskyguru<br />Facebook: http://www.facebook.com/multimegaitschool<br />Chat, Forum, Group: http://www.cs-school.com/forums <br /><br />
<br /><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-46847915622109018002016-08-09T05:29:00.001-07:002016-08-09T05:29:51.420-07:00How to generate a session number in java [Real Project]<br /><br />
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/GZtP9HJuKfg" width="480"></iframe><br />
<br />
<br /><br />
<br /><br />
Alright, Guys in this tutorial i taught u Guys how to generate Session numbers, primary keys, unique numbers in java...<br /><br />
<br />Project Materials► https://cs-school.com/<br /><br />Twitter ► http://www.twitter.com/kaperskyguru<br />Website ► http://www.cs-school.com<br />Facebook ► http://www.facebook.com/multimegaitsc...<br /><br />Want more? You can join thousand of members to discover more about computer science, technology, programming.. visit: http://www.cs-school.com<br /><br />-------------------------------------------------------------------------------------------------<br /><br />Website: http://www.cs-school.com<br />Twitter: http://www.twitter.com/kaperskyguru<br />Facebook: http://www.facebook.com/multimegaitsc...<br />Chat, Forum, Group: http://www.cs-school.com/forums <div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-80348344302790029162016-07-21T06:28:00.001-07:002016-07-21T06:33:16.186-07:00Microsoft Excel 2016 - Ep. 4 - Fixing Up And Introducing AutoSum<div dir="ltr" style="text-align: left;" trbidi="on">
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/mmpgBpmXRpQ" width="480"></iframe><br />
<br />
<br />
<br />
<br />
<br />
Microsoft Excel 2016 - Ep. 4 - Fixing Up And Introducing AutoSum...<br />
<br />
Project Materials► https://cs-school.com/<br />
<br />
Twitter ► http://www.twitter.com/kaperskyguru<br />
<br />
Website ► http://www.cs-school.com<br />
<br />
Facebook ► http://www.facebook.com/multimegaitschool<br />
<br />
Want more? You can join thousand of members to discover more about computer science, technology, programming.. visit: http://www.cs-school.com<br />
<br />
-------------------------------------------------------------------------------------------------<br />
<br />
Website: http://www.cs-school.com<br />
<br />
Twitter: http://www.twitter.com/kaperskyguru<br />
<br />
Facebook: http://www.facebook.com/multimegaitschool<br />
<br />
Chat, Forum, Group: http://www.cs-school.com/forums</div>
<div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-88262489036832040742016-01-22T20:23:00.001-08:002016-01-22T20:23:56.233-08:00HOW TO HOST A WEBSITE FROM SCRATCH<br /><br />
<br /><br />
<br /><br />
<br /><br />
<br /><br />
<br /><br />
<br /><br />
<br /><br />
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/R5a4Rujxc8E" width="480"></iframe><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0tag:blogger.com,1999:blog-3451107919319470198.post-82372582187737723852016-01-22T09:27:00.001-08:002016-01-22T09:27:08.504-08:00how to spam a Paypal login and other information by Opa7even Da'Cyberkn...<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/rI54qB1iR6o" width="480"></iframe><div class="blogger-post-footer">WE APPRECIATE YOUR COMMENTS</div>Solomon esemehttp://www.blogger.com/profile/10768243204574056273noreply@blogger.com0