title: Laravel -5: How do I get my form inputs to validate (among other things..)?
body: <p>I have a few problems.</p>
  
  <ol>
  <li>I can't seem to display the saved data inside my form inputs.</li>
  <li>I can't get my urls to validate unique. </li>
  <li>My controller code looks very redundant.</li>
  </ol>
  
  <p>Getting the urls to validate unique takes priority though.</p>
  
  <p>Also I created the table for sharing social links with a user one to many relationship. I think thats correct.  If not, please correct me.</p>
  
  <p><strong>update</strong>  Just a thought...I think I'm probably complicating things by only have a single 'type' column.  It would be easier if I had a column for each type of link i.e facebook col, twitter col etc.  I just didn't want empty columns if user didn't provide info for some services
  Heres my code:</p>
  
  <p><strong>UPDATE</strong> I gave up and just added individual columns for the different types of urls and changed to a one-to-one relationship.  </p>
  
  <p><strong>form</strong></p>
  
  <pre><code>{!! Form::model($user_links,['method' =&gt; 'PATCH', 'action'=&gt; ['UserController@update_social']]) !!}
                  &lt;div class='row form-group'&gt;
                      &lt;div class='col-md-2'&gt;
                          {!! Form::label('facebook', 'Facebook Username') !!}
                      &lt;/div&gt;
                      &lt;div class='col-md-7'&gt;
                          {!! Form::text('facebook', '',['class'=&gt;'form-control']) !!}
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class='row form-group'&gt;
                      &lt;div class='col-md-2'&gt;
                          {!! Form::label('twitter', 'Twitter Username') !!}
                      &lt;/div&gt;
                      &lt;div class='col-md-7'&gt;
                          {!! Form::text('twitter', null,['class'=&gt;'form-control']) !!}
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class='row form-group'&gt;
                      &lt;div class='col-md-2'&gt;
                          {!! Form::label('reddit', 'Reddit Username') !!}
                      &lt;/div&gt;
                      &lt;div class='col-md-7'&gt;
                          {!! Form::text('reddit', null,['class'=&gt;'form-control']) !!}
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class='row form-group'&gt;
                      &lt;div class='col-md-3'&gt;
                          {!! Form::submit('Save Changes',['class'=&gt;'btn btn-md btn-success']) !!}
                      &lt;/div&gt;
                  &lt;/div&gt;
                  {!! Form::close() !!}
  </code></pre>
  
  <p><strong>controllers</strong></p>
  
  <pre><code>    public function show_social(Request $request){
        $user_links= $request-&gt;user()-&gt;links;
        return view('user.edit.social_connect',compact('user_links'));
      }
  
      public function update_social(SocialRequest $request){
        $facebook= Input::get('facebook');
        $twitter= Input::get('twitter');
        $reddit= Input::get('reddit');
        $user = $request-&gt;user();
  
        $this-&gt;validate($request,['url'=&gt;'unique']);
  
        if(Input::has('facebook')||Input::has('google')||Input::has('reddit')||Input::has('twitter'))
        {
          if($facebook != ""){
            $link = new SocialLinks();
            $link-&gt;type = 'facebook';
            $link-&gt;url='https//www.facebook.com/'.$facebook;
            $link-&gt;user_id=$user-&gt;id;
            $link-&gt;save(); 
          }
          if($twitter != ""){
            $link = new SocialLinks();
            $link-&gt;type = 'twitter';
            $link-&gt;url='https//www.twitter.com/'.$twitter;
            $link-&gt;user_id=$user-&gt;id;
            $link-&gt;save(); 
          }
          if($reddit != ""){
            $link = new SocialLinks();
            $link-&gt;type = 'reddit';
            $link-&gt;url='https//www.reddit.com/user'.$reddit;
            $link-&gt;user_id=$user-&gt;id;
            $link-&gt;save(); 
          }
          return Redirect::back()-&gt;with('message','Your profile has been updated');     
        }
          return Redirect::back();
  
      }
  </code></pre>
  
  <p><strong>my model file</strong></p>
  
  <pre><code>&lt;?php
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  use Eloquent;
  
  class SocialLinks extends Eloquent{
  
      protected $table= 'social_links';
  
      protected $fillable=[
          'type',
          'url'                                       
      ];
      public function user()
      {
          return $this-&gt;belongsTo('App\User');
      }
  
  }
  ?&gt;
  </code></pre>
  
  <p>my request </p>
  
  <pre><code>&lt;?php
  namespace App\Http\Requests;
  
  use App\Http\Requests\Request;
  
  class SocialRequest extends Request
  {
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          return true;
      }
  
  
      /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
      public function rules()
      {
  
              return [
                  'url'=&gt;'unique|user_id'      
                  ];
              }
  
  }
  </code></pre>