2015-11-13 22 views
2

我目前laravel努力讓非對象laravel的財產,我用從GitHub顏色提取從圖片(JPG或PNG)得到三個最突出的顏色。這工作,檢查PrtSc鍵:嘗試使用顏色提取

Color extractor picture

正如你可以看到六碼鏈接,當你點擊你應該看到的每一篇文章,其中hexacode是最突出的顏色之一的鏈接。 當我點擊鏈接時,我得到一個「試圖獲取非對象的屬性」錯誤。

這是在我的控制器的功能得到人的文章:

public function getTag($tag) 
{ 

    $articles = Article::where('tags', 'LIKE', '%'.$tag.'%')->get(); 


    return view("article.tagFilter")->with('articles',$articles); 
} 

public function getColor($color) 
{ 
    $articles = Article::where('color', 'LIKE', '%'.$color.'%')->get(); 


    return view("article.tagFilter")->with('articles',$articles); 
} 

功能getTag是完全相同,這個功能確實工作。

這是我負載,可以在圖像上看到上面的視圖功能。

public function showArticle($id) 
{ 
    $article = Article::find($id); 
    $comments = DB::table('comments') 
       ->select('*') 
       ->where('article_id', '=', $id) 
       ->join('users', 'users.id', '=', 'user_id') 
       ->get(); 
    $myString = $article->tags; 
    $myColorString = $article->color; 
    $myArray = explode(',', $myString); 
    $myColorArray = explode(',',$myColorString); 

    return view('article.show')->with('article',$article)>with('myArray',$myArray)->with('comments',$comments)->with('myColorArray',$myColorArray); 
} 

這是視圖的一部分,我展示hexacodes:

<?php 
for ($i = 0; $i < count($myColorArray); ++$i) { 

?><a href="/articles/color/{{$myColorArray[$i]}}"><p> 

     <?php 
     print "#".$myColorArray[$i]; 
     ?> 

    </p></a> 
<?php 
} 
?> 

最後但並非最不重要的路線我用:

Route::get('articles/color/{color}','[email protected]'); 

我希望你們能幫助我!

+0

在你得到了什麼線什麼文件的非對象錯誤的財產? –

+0

$ myString = $ article-> tags;在showArticle函數中。但有趣的是,我可以在這種情況下,「flopsie」標籤篩選,但我不能對你 –

+0

將呼叫路由'getColor'的顏色過濾器,但你說'showArticle'是什麼問題? –

回答

0

我發現我的錯誤。當我點擊鏈接laravel認爲我要去另一條路線。它使用下面的一個:

Route::get('articles/{id}/{title}', '[email protected]'); 

雖然我的其他路線是在列表中的這一個。我不得不把路線放在tagController @ getColor上面。

相關問題