Skip to content

Instantly share code, notes, and snippets.

@matgargano
Created January 25, 2016 15:29
Show Gist options
  • Save matgargano/62c91eefffb71d3ae154 to your computer and use it in GitHub Desktop.
Save matgargano/62c91eefffb71d3ae154 to your computer and use it in GitHub Desktop.
Laravel
@extends('layouts.app')
@section('content')
@foreach($models as $model)
{{ $model->key }}
@endforeach
{!! Form::open((array('action' => 'ProfilesController@store'))) !!}
<input type="text" value="">
<input type="submit" value="Submit">
{!! Form::close() !!}
@stop
<?php
namespace SundaySim\Http\Controllers;
use Illuminate\Http\Request;
use SundaySim\Http\Requests;
use SundaySim\UserMeta;
class ProfilesController extends Controller {
public function index( Request $auth ) {
$id = $auth->user()->id;
$models = UserMeta::where( 'user_id', $id )->get();
return view( 'profile.main' )->with( 'models', [ 'models' => $model ] );
}
}
<?php
namespace SundaySim;
use Illuminate\Database\Eloquent\Model;
class UserMeta extends Model
{
protected $fillable = [
'key', 'value', 'user_id',
];
public function user_id() {
return $this->belongsToMany('App\User', 'user_id', 'id'); // user_id on this model is a foreign key to id on app/user
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment