2017-12-14 18 views
0

ビューからルートへ$ idパラメータを渡すにはどうすればよいですか?私はよく知っていないlaravelちょうど私は学んでいる。ルートパラメータでデータを取得

私のコントローラ

class YayinController extends Controller 
{ 
public function index(){ 

    return view ('yayin.canli'); 
} 

public function hamleler($id){ 


    $notations=Notasyon::where('id',$id)->orderBy('id', 'desc')->first(); 
    if($id==$notations->id){ 
     $lastgame=$notations->hamle; 
     return response()->json($lastgame); 

    } 
    } 
    } 

私は、このid値に応じてデータを受信し、VIEW1にそれを送りたいです。

データベースデータのIDがパラメータのIDと同じ場合、データは10秒間引き出され続けます。私は(ビューgetjsondata()内の)データのスクリプトコードでこれをやりたい

ルート

Route::get('/canli-yayin/','[email protected]'); 
    Route::get('/canli-yayin/hamleler/{id?}','[email protected]'); 

あなたはroute()のようなヘルパーのいずれかを使用することができます

function getjsondata() { 



$.get("{{URL::To('canli-yayin/hamleler/')}}", function(data) { 


     if(data) { 
document.getElementById("notasyon").innerHTML=document.getElementById("notasyon").innerHTML+data+" "; 

} 
else { 
     alert('error'); 
     } 
     }); 
     } 

$(document).ready(function(){ 
     setInterval(getjsondata,3000) 

    }) 
+0

ハジュのID TAM olarakのneredenのgelip、nereyeのgidiyor?あなたは私の兄弟のように見えるのですか? –

+0

ビューイングゼンマイジェレク。表示されているバージョンを確認するには、Setintervalファイルを3回実行してください。それはあなたの意見を反映しています。 bunuda、ControllerdのIDは、この脆弱性の脆弱性を悪用するものではありません。 Bununの写真は、1件のartırmamlazımsanırım。 –

+0

viewin ilgilikısmınıekleseneバイsoruya –

答えて

0

canli.blade.php名前付きルートの場合はurl()

{{ url('canli-yayin/hamleler', [$id]) }} 

あなたが$idを取得する必要があり方法:

public function hamleler($id) 
0

正規形が

<form class="form-vertical" role="form" method="post" action="{{ route('/canli-yayin/hamleler', [$id])}}"> 

フォームがアヤックスに

var id = "getting it from blade" 

     $.ajax({ 
      url:'/canli-yayin/hamleler/'+id, 
      type:"POST", 
      success:function(response){ 
      }, 
     }); 

ウェブルート

を使用して提出提出
Route::get('/canli-yayin/hamleler/{id?}','[email protected]'); 

コントローラ

class YayinController extends Controller 
{ 
public function index(){ 

    return view ('yayin.canli'); 
} 

    public function hamleler($id){ 

     dd($id); 
     $notations=Notasyon::orderBy('id', 'desc')->first(); 
     $lastgame=$notations->hamle; 
     return response()->json($lastgame); 

     } 

    } 
+0

ビューのid値を変更してコントローラに送り返すことはできますか? –

+0

はい、変更できます。 –

+0

いいです、どうすればいいですか? [$ id]の代わりに –