75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Models\Blog;
|
|
use App\Models\Category;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class NewsAhrom extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
try {
|
|
$news_ahrom = Blog::where('notBlog' , 1)->where('status' , 1)->orderByDesc('created_at')->get()->take(5);
|
|
$news_ahromArray= [] ;
|
|
foreach ($news_ahrom as $key => $new) {
|
|
$check = Category::where('id' , $new['category_array'])->first();
|
|
if ( $check->slug == 'ahrom') {
|
|
$news_ahromArray []= [
|
|
'success' => true,
|
|
'title' => $blog->subject,
|
|
'published_at' => $blog->created_at,
|
|
];
|
|
}
|
|
}
|
|
return response()->json([
|
|
'data' => $news_ahromArray ,
|
|
'message' => 'اطلاعات با موفقیت ارسال شد'
|
|
], 200);
|
|
|
|
} catch (\Exception $e) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'مشکلی در دریافت اطلاعات پیش آمده: ' . $e->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
//
|
|
}
|
|
}
|