【问题标题】:How to pull data from the database-Laravel如何从数据库中拉取数据-Laravel
【发布时间】:2019-09-21 09:09:50
【问题描述】:
class LeavesController extends Controller
    {
    public function pullCon()

    {
        return json_encode(Leaves::all());
    }

    }

    this is my route



    Route::get('/folder/leaves', 'LeavesController@pullMetod');






    and this is my json why wont it work


     $(document).ready(function(){

     $.ajax({

            url:"/folder/leaves",

            type: "get",

            success: function(resuLt)
            {

                consoLe.log(result);
                let obj = JSON.parse(result);
                consoLe.log(obj);
                $("table").append(<tr> <td>ID</td> <td>Name</td> <td>Mass</td> 
       <td>Year</td> </tr>);
                for( let i=0; i<obj.lenght; i++)
                {
                    $("table").append('<tr>');
                    $("table").append('<td>' + obj[i].id + '</td>');
                    $("table").append('<td>' + obj[i].earth_mass + '</td>');
                    $("table").append('<td>' + obj[i].year_lenght + '</td>');
                    $("table").append('</tr>');
                }
            }

        });

        });

它需要学说/dbal 作为依赖项。但是一些迁移功能已经需要 DBAL 才能工作。确保您填写 table_catalog (我猜它等同于数据库)。您可能需要稍微调整一下结果。

【问题讨论】:

  • 在 ajax({}}) 你使用 dataType:'json',

标签: php laravel numbers


【解决方案1】:
class SongController extends Controller
{
 public function dovuci()
 {
    $PParniValjak = Song::where("band_name","=","ParniValjak")
    ->where("length",">",300)
    ->get();

    foreach($PParniValjak as $pesma)
    {
        $pesma->lenght /= 60;
    }

    return view ('pesme_podaci')->with('ParniValjak',$PParniValjak);
 }
 public function obrisi()
 {
    $PParniValjak = Song::where("band_name","=","Parni valjak")
    ->where("id","asc")
    ->get();

    $PParniValjak = $PParniValjak->splice(1);
    foreach($PParniValjak as $pesma)
    {
        print_r(pesma);
        $pesma->delete();
       }
    }
}   

我认为这是你的控制器

【讨论】:

    【解决方案2】:
     <!DOCTYPE html>
    <html>
    <head>
    
    
    
    </head>
    <body>
    <table>
        tr
            th Band Name:/th           
            th Song Name: /th
            th >Band lenght:/th
        /tr
            @foreach(@CrvenaJabuka as $pesme)
                tr
                    td{{$pesma->band_name}}/td
                    td{{$pesma->song_name}}/td
                    td{{$number_format($pesma->lenght,2)->band_name}}/td
                /tr
            @endforeach
     </table>
    

    这是你的歌曲数据

    【讨论】:

      猜你喜欢
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 2022-12-01
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多