Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [inny][Laravel5] Formularz model relacja wiele do wielu
nospor
post
Post #1





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




Hej, masz Posty i tagi. Posty mogą mieć wiele tagow, tag moze należec do wielu postow.
  1. class Post extends Model {
  2.  
  3. protected $fillable = [
  4. 'title', 'post', 'publish_at'
  5. ];
  6.  
  7. protected $dates = ['publish_at'];
  8.  
  9. public function tags()
  10. {
  11. return $this->belongsToMany('App\Tag');
  12. }
  13.  
  14. }

  1. class Tag extends Model {
  2.  
  3. protected $fillable = [
  4. 'name', 'namelink'
  5. ];
  6.  
  7. public $timestamps = false;
  8.  
  9.  
  10. }


Mam teraz formularz edycji posta:
Kod
{(IMG:style_emoticons/default/exclamation.gif) Form::model($post, ['route'=>['post.update', $post->id], 'method'=>'PATCH', 'class' => 'form-horizontal']) (IMG:style_emoticons/default/exclamation.gif) }
<div class="form-group">
    {(IMG:style_emoticons/default/exclamation.gif) Form::label('post', 'Postaa', array('class' => 'col-sm-2 control-label')) (IMG:style_emoticons/default/exclamation.gif) }
    <div class="col-sm-10">
        {(IMG:style_emoticons/default/exclamation.gif) Form::textarea('post', null, ['class'=>'form-control', 'id'=>'post', 'placeholder'=>'Post']) (IMG:style_emoticons/default/exclamation.gif) }
    </div>
</div>
{(IMG:style_emoticons/default/exclamation.gif) Form::close() (IMG:style_emoticons/default/exclamation.gif) }

Ale chcę do tego dodać jeszcze textarea gdzie po przecinkach czy enterach będą nazwy tagow, ktore ma dany post. Jak to moge zrobić?
Moge to zrobic prymitywnie, czyli w kontrolerze pobrac tagi z posta, połączyc czym chce i wrzucic do widoku, ale kurcze, nie po to mam Modele i zaleznosci by tak robic. Idzie to jakoś zautomatyzowac? Skoro jedne pola form łyka automatycznie, to moze się da by łykał też relacje?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 5.10.2025 - 20:17