Edit a dropdown list for a foreign key Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Get first key in a (possibly) associative array?PHP array delete by value (not key)ZF2 Form Collection with fieldset stays in old state if validation failsCannot upload picture in laravel 4Validating fields based on label classPOST 500 (Internal Server Error) AjaxLaravel Spark API call validation not returning errors on fail but showing login pageLaravel ignores select input validation if no option is selectedPusher add CSRF token to form dataWhat Are The Causes of Laravel 5.5 “MethodNotAllowedHttpException”

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

What is "gratricide"?

How to play a character with a disability or mental disorder without being offensive?

What is the topology associated with the algebras for the ultrafilter monad?

What would you call this weird metallic apparatus that allows you to lift people?

How to tell that you are a giant?

How do living politicians protect their readily obtainable signatures from misuse?

How much damage would a cupful of neutron star matter do to the Earth?

Do I really need to have a message in a novel to appeal to readers?

Is grep documentation about ignoring case wrong, since it doesn't ignore case in filenames?

How come Sam didn't become Lord of Horn Hill?

Question about debouncing - delay of state change

What was the first language to use conditional keywords?

Can a new player join a group only when a new campaign starts?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

Project Euler #1 in C++

Disembodied hand growing fangs

Take 2! Is this homebrew Lady of Pain warlock patron balanced?

How do I use the new nonlinear finite element in Mathematica 12 for this equation?

Selecting user stories during sprint planning

Did Deadpool rescue all of the X-Force?

Can anything be seen from the center of the Boötes void? How dark would it be?

A term for a woman complaining about things/begging in a cute/childish way

Why is it faster to reheat something than it is to cook it?



Edit a dropdown list for a foreign key



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Get first key in a (possibly) associative array?PHP array delete by value (not key)ZF2 Form Collection with fieldset stays in old state if validation failsCannot upload picture in laravel 4Validating fields based on label classPOST 500 (Internal Server Error) AjaxLaravel Spark API call validation not returning errors on fail but showing login pageLaravel ignores select input validation if no option is selectedPusher add CSRF token to form dataWhat Are The Causes of Laravel 5.5 “MethodNotAllowedHttpException”



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a table named marks with 2 fields id, name_mark. Then, I have another table named series with 3 fields id, name, fk_mark.



My goal is to create an edit system. My first problem is in the dropdown list of my foreign key (fk_mark), I always have the same item in each line.



enter image description here



Here is my SerieController



public function edit($id)

$series = Serie::find($id);
$marks = Mark::find($id);
return view('admin.series.edit', compact('marks', 'series'));

public function update(Request $request, $id)
string',
'fk_mark' => 'required'
]);
$series = Serie::find($id);
$series->name = $request->get('name');
$series->fk_mark = $request->get('fk_mark');
$series->save();
return redirect()->route('series.index')
->with('success', 'updated successfully');



In my series.edit.blade I have this



<form class="panel-body" action="route('series.update',$marks->id)" method="POST">
<input name="_method" type="hidden" value="PATCH">
@csrf
<fieldset class="form-group">
<label for="form-group-input-1">Nom</label>
<input type="text" name="name" class="form-control" id="form-group-input-1" value="$series->nom">
</fieldset>
<div class="form-group">
<label for="company-content">Select Mark</label>
<select name="fk_mark" id="" class="form-control">
@foreach($marks as $mark)
<option value="$marks->id">
$marks->name_mark
</option>
@endforeach
</select>
</div>









share|improve this question






























    0















    I have a table named marks with 2 fields id, name_mark. Then, I have another table named series with 3 fields id, name, fk_mark.



    My goal is to create an edit system. My first problem is in the dropdown list of my foreign key (fk_mark), I always have the same item in each line.



    enter image description here



    Here is my SerieController



    public function edit($id)

    $series = Serie::find($id);
    $marks = Mark::find($id);
    return view('admin.series.edit', compact('marks', 'series'));

    public function update(Request $request, $id)
    string',
    'fk_mark' => 'required'
    ]);
    $series = Serie::find($id);
    $series->name = $request->get('name');
    $series->fk_mark = $request->get('fk_mark');
    $series->save();
    return redirect()->route('series.index')
    ->with('success', 'updated successfully');



    In my series.edit.blade I have this



    <form class="panel-body" action="route('series.update',$marks->id)" method="POST">
    <input name="_method" type="hidden" value="PATCH">
    @csrf
    <fieldset class="form-group">
    <label for="form-group-input-1">Nom</label>
    <input type="text" name="name" class="form-control" id="form-group-input-1" value="$series->nom">
    </fieldset>
    <div class="form-group">
    <label for="company-content">Select Mark</label>
    <select name="fk_mark" id="" class="form-control">
    @foreach($marks as $mark)
    <option value="$marks->id">
    $marks->name_mark
    </option>
    @endforeach
    </select>
    </div>









    share|improve this question


























      0












      0








      0








      I have a table named marks with 2 fields id, name_mark. Then, I have another table named series with 3 fields id, name, fk_mark.



      My goal is to create an edit system. My first problem is in the dropdown list of my foreign key (fk_mark), I always have the same item in each line.



      enter image description here



      Here is my SerieController



      public function edit($id)

      $series = Serie::find($id);
      $marks = Mark::find($id);
      return view('admin.series.edit', compact('marks', 'series'));

      public function update(Request $request, $id)
      string',
      'fk_mark' => 'required'
      ]);
      $series = Serie::find($id);
      $series->name = $request->get('name');
      $series->fk_mark = $request->get('fk_mark');
      $series->save();
      return redirect()->route('series.index')
      ->with('success', 'updated successfully');



      In my series.edit.blade I have this



      <form class="panel-body" action="route('series.update',$marks->id)" method="POST">
      <input name="_method" type="hidden" value="PATCH">
      @csrf
      <fieldset class="form-group">
      <label for="form-group-input-1">Nom</label>
      <input type="text" name="name" class="form-control" id="form-group-input-1" value="$series->nom">
      </fieldset>
      <div class="form-group">
      <label for="company-content">Select Mark</label>
      <select name="fk_mark" id="" class="form-control">
      @foreach($marks as $mark)
      <option value="$marks->id">
      $marks->name_mark
      </option>
      @endforeach
      </select>
      </div>









      share|improve this question
















      I have a table named marks with 2 fields id, name_mark. Then, I have another table named series with 3 fields id, name, fk_mark.



      My goal is to create an edit system. My first problem is in the dropdown list of my foreign key (fk_mark), I always have the same item in each line.



      enter image description here



      Here is my SerieController



      public function edit($id)

      $series = Serie::find($id);
      $marks = Mark::find($id);
      return view('admin.series.edit', compact('marks', 'series'));

      public function update(Request $request, $id)
      string',
      'fk_mark' => 'required'
      ]);
      $series = Serie::find($id);
      $series->name = $request->get('name');
      $series->fk_mark = $request->get('fk_mark');
      $series->save();
      return redirect()->route('series.index')
      ->with('success', 'updated successfully');



      In my series.edit.blade I have this



      <form class="panel-body" action="route('series.update',$marks->id)" method="POST">
      <input name="_method" type="hidden" value="PATCH">
      @csrf
      <fieldset class="form-group">
      <label for="form-group-input-1">Nom</label>
      <input type="text" name="name" class="form-control" id="form-group-input-1" value="$series->nom">
      </fieldset>
      <div class="form-group">
      <label for="company-content">Select Mark</label>
      <select name="fk_mark" id="" class="form-control">
      @foreach($marks as $mark)
      <option value="$marks->id">
      $marks->name_mark
      </option>
      @endforeach
      </select>
      </div>






      php laravel






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 at 4:33









      Udhav Sarvaiya

      2,57892131




      2,57892131










      asked Mar 8 at 20:33









      user11124425user11124425

      928




      928






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Looks like your problem is the variable you're using. You're using $marks instead of $mark.



          Your code:



          @foreach($marks as $mark)
          <option value="$marks->id">$marks->name_mark


          Try this:



          @foreach($marks as $mark)
          <option value="$mark->id">$mark->name_mark


          Another problem you're having, is that you're trying to retrieve a list for Marks but you're using a find method, how's brings the values by the key. This method suppose to bring just one record. Try method where. With a different field. This gonna bring a list of records.






          share|improve this answer

























          • Thank you but I have this error message "Trying to get property 'id' of non-object ; I think it's in my SerieController here ? public function edit($id) $series = Serie::find($id); $marks = Mark::find($id); return view('admin.series.edit', compact('marks', 'series'));

            – user11124425
            Mar 8 at 20:52






          • 2





            the you should try this $mark['id'

            – Muhammad Shareyar
            Mar 8 at 20:54






          • 1





            try to debug what actually you are getting in your $marks or $series variable like dd($marks)

            – Muhammad Shareyar
            Mar 8 at 20:55











          • @ Muhammad Shareyar: I get the same item everyimes. In the SerieController, I can have several models in fact?

            – user11124425
            Mar 9 at 11:44











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070606%2fedit-a-dropdown-list-for-a-foreign-key%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Looks like your problem is the variable you're using. You're using $marks instead of $mark.



          Your code:



          @foreach($marks as $mark)
          <option value="$marks->id">$marks->name_mark


          Try this:



          @foreach($marks as $mark)
          <option value="$mark->id">$mark->name_mark


          Another problem you're having, is that you're trying to retrieve a list for Marks but you're using a find method, how's brings the values by the key. This method suppose to bring just one record. Try method where. With a different field. This gonna bring a list of records.






          share|improve this answer

























          • Thank you but I have this error message "Trying to get property 'id' of non-object ; I think it's in my SerieController here ? public function edit($id) $series = Serie::find($id); $marks = Mark::find($id); return view('admin.series.edit', compact('marks', 'series'));

            – user11124425
            Mar 8 at 20:52






          • 2





            the you should try this $mark['id'

            – Muhammad Shareyar
            Mar 8 at 20:54






          • 1





            try to debug what actually you are getting in your $marks or $series variable like dd($marks)

            – Muhammad Shareyar
            Mar 8 at 20:55











          • @ Muhammad Shareyar: I get the same item everyimes. In the SerieController, I can have several models in fact?

            – user11124425
            Mar 9 at 11:44















          3














          Looks like your problem is the variable you're using. You're using $marks instead of $mark.



          Your code:



          @foreach($marks as $mark)
          <option value="$marks->id">$marks->name_mark


          Try this:



          @foreach($marks as $mark)
          <option value="$mark->id">$mark->name_mark


          Another problem you're having, is that you're trying to retrieve a list for Marks but you're using a find method, how's brings the values by the key. This method suppose to bring just one record. Try method where. With a different field. This gonna bring a list of records.






          share|improve this answer

























          • Thank you but I have this error message "Trying to get property 'id' of non-object ; I think it's in my SerieController here ? public function edit($id) $series = Serie::find($id); $marks = Mark::find($id); return view('admin.series.edit', compact('marks', 'series'));

            – user11124425
            Mar 8 at 20:52






          • 2





            the you should try this $mark['id'

            – Muhammad Shareyar
            Mar 8 at 20:54






          • 1





            try to debug what actually you are getting in your $marks or $series variable like dd($marks)

            – Muhammad Shareyar
            Mar 8 at 20:55











          • @ Muhammad Shareyar: I get the same item everyimes. In the SerieController, I can have several models in fact?

            – user11124425
            Mar 9 at 11:44













          3












          3








          3







          Looks like your problem is the variable you're using. You're using $marks instead of $mark.



          Your code:



          @foreach($marks as $mark)
          <option value="$marks->id">$marks->name_mark


          Try this:



          @foreach($marks as $mark)
          <option value="$mark->id">$mark->name_mark


          Another problem you're having, is that you're trying to retrieve a list for Marks but you're using a find method, how's brings the values by the key. This method suppose to bring just one record. Try method where. With a different field. This gonna bring a list of records.






          share|improve this answer















          Looks like your problem is the variable you're using. You're using $marks instead of $mark.



          Your code:



          @foreach($marks as $mark)
          <option value="$marks->id">$marks->name_mark


          Try this:



          @foreach($marks as $mark)
          <option value="$mark->id">$mark->name_mark


          Another problem you're having, is that you're trying to retrieve a list for Marks but you're using a find method, how's brings the values by the key. This method suppose to bring just one record. Try method where. With a different field. This gonna bring a list of records.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 10 at 15:59

























          answered Mar 8 at 20:38









          Pablo CastroPablo Castro

          646




          646












          • Thank you but I have this error message "Trying to get property 'id' of non-object ; I think it's in my SerieController here ? public function edit($id) $series = Serie::find($id); $marks = Mark::find($id); return view('admin.series.edit', compact('marks', 'series'));

            – user11124425
            Mar 8 at 20:52






          • 2





            the you should try this $mark['id'

            – Muhammad Shareyar
            Mar 8 at 20:54






          • 1





            try to debug what actually you are getting in your $marks or $series variable like dd($marks)

            – Muhammad Shareyar
            Mar 8 at 20:55











          • @ Muhammad Shareyar: I get the same item everyimes. In the SerieController, I can have several models in fact?

            – user11124425
            Mar 9 at 11:44

















          • Thank you but I have this error message "Trying to get property 'id' of non-object ; I think it's in my SerieController here ? public function edit($id) $series = Serie::find($id); $marks = Mark::find($id); return view('admin.series.edit', compact('marks', 'series'));

            – user11124425
            Mar 8 at 20:52






          • 2





            the you should try this $mark['id'

            – Muhammad Shareyar
            Mar 8 at 20:54






          • 1





            try to debug what actually you are getting in your $marks or $series variable like dd($marks)

            – Muhammad Shareyar
            Mar 8 at 20:55











          • @ Muhammad Shareyar: I get the same item everyimes. In the SerieController, I can have several models in fact?

            – user11124425
            Mar 9 at 11:44
















          Thank you but I have this error message "Trying to get property 'id' of non-object ; I think it's in my SerieController here ? public function edit($id) $series = Serie::find($id); $marks = Mark::find($id); return view('admin.series.edit', compact('marks', 'series'));

          – user11124425
          Mar 8 at 20:52





          Thank you but I have this error message "Trying to get property 'id' of non-object ; I think it's in my SerieController here ? public function edit($id) $series = Serie::find($id); $marks = Mark::find($id); return view('admin.series.edit', compact('marks', 'series'));

          – user11124425
          Mar 8 at 20:52




          2




          2





          the you should try this $mark['id'

          – Muhammad Shareyar
          Mar 8 at 20:54





          the you should try this $mark['id'

          – Muhammad Shareyar
          Mar 8 at 20:54




          1




          1





          try to debug what actually you are getting in your $marks or $series variable like dd($marks)

          – Muhammad Shareyar
          Mar 8 at 20:55





          try to debug what actually you are getting in your $marks or $series variable like dd($marks)

          – Muhammad Shareyar
          Mar 8 at 20:55













          @ Muhammad Shareyar: I get the same item everyimes. In the SerieController, I can have several models in fact?

          – user11124425
          Mar 9 at 11:44





          @ Muhammad Shareyar: I get the same item everyimes. In the SerieController, I can have several models in fact?

          – user11124425
          Mar 9 at 11:44



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070606%2fedit-a-dropdown-list-for-a-foreign-key%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко