changed avatar url in both old and new EDIT APIs| removed db raw from road items report| changed url in Randd

This commit is contained in:
2024-10-01 13:12:12 +00:00
parent bc4ae8d3a8
commit 7678ed9298
8 changed files with 17 additions and 14 deletions

View File

@@ -16,6 +16,7 @@ use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use App\Models\RandDVoting; use App\Models\RandDVoting;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Support\Facades\URL;
use App\Models\RandDVotingPaperAnswer; use App\Models\RandDVotingPaperAnswer;
class NewRandDCtrl extends Controller class NewRandDCtrl extends Controller
@@ -125,7 +126,7 @@ class NewRandDCtrl extends Controller
$item->setAttribute('Voting', true); $item->setAttribute('Voting', true);
$getVote = RandDVoting::where('project_id', $item->id)->where('status', '2')->first(); $getVote = RandDVoting::where('project_id', $item->id)->where('status', '2')->first();
if (! RandDVotingPaperAnswer::where('vote_id', $getVote->id)->where('user_id', Auth::user()->id)->first()) { if (! RandDVotingPaperAnswer::where('vote_id', $getVote->id)->where('user_id', Auth::user()->id)->first()) {
$url = 'https://rms.rmto.ir/randd/voting/' . $getVote->id; $url = URL::to('/randd/voting') . '/'. $getVote->id;
$item->setAttribute('urlVoting', $url); $item->setAttribute('urlVoting', $url);
$item->setAttribute('allowVoting', true); $item->setAttribute('allowVoting', true);

View File

@@ -13,6 +13,7 @@ use App\Models\User;
use Carbon\Carbon; use Carbon\Carbon;
use App\Models\City; use App\Models\City;
use App\Models\Province; use App\Models\Province;
use Illuminate\Support\Facades\File;
use App\Models\EdarateShahri; use App\Models\EdarateShahri;
use App\Models\EdarateOstani; use App\Models\EdarateOstani;
use Cache; use Cache;
@@ -2111,7 +2112,7 @@ class UserController extends Controller
$user->save(); $user->save();
if ($request->has('avatar')) { if ($request->has('avatar')) {
Storage::delete('public/' . $user->avatar); File::delete($user->avatar);
$destinationPath = 'avatar/' . $user->username; $destinationPath = 'avatar/' . $user->username;
$filename = time() .".". $request->file('avatar')->getClientOriginalExtension(); $filename = time() .".". $request->file('avatar')->getClientOriginalExtension();
$request->file('avatar')->storeAs($destinationPath, $filename, 'public'); $request->file('avatar')->storeAs($destinationPath, $filename, 'public');

View File

@@ -90,9 +90,7 @@ class RoadItemsReportController extends Controller
$province = $request->province_id; $province = $request->province_id;
$all = array(); $all = array();
$all = DB::select( $all = DB::select(
DB::raw(
'SELECT sub_item AS t,COUNT(*) AS c,CAST(SUM(CASE WHEN sub_item_data>0 THEN sub_item_data ELSE ABS(sub_item_data) END) AS UNSIGNED) AS s,province_id AS p, edarat_id AS ci FROM road_items_projects WHERE item = ' . $item . ' AND province_id = ' . $province . ' AND activity_date_time BETWEEN "' . $from_date . '" AND "' . $date_to . '" and status = 1 GROUP BY ci, sub_item' 'SELECT sub_item AS t,COUNT(*) AS c,CAST(SUM(CASE WHEN sub_item_data>0 THEN sub_item_data ELSE ABS(sub_item_data) END) AS UNSIGNED) AS s,province_id AS p, edarat_id AS ci FROM road_items_projects WHERE item = ' . $item . ' AND province_id = ' . $province . ' AND activity_date_time BETWEEN "' . $from_date . '" AND "' . $date_to . '" and status = 1 GROUP BY ci, sub_item'
)
); );
$items_fa = InfoItem::where('item', $item)->get(); $items_fa = InfoItem::where('item', $item)->get();
foreach ($all as $value) { foreach ($all as $value) {

View File

@@ -9,6 +9,7 @@ use App\Http\Requests\V3\Profile\EditRequest;
use App\Http\Traits\ApiResponse; use App\Http\Traits\ApiResponse;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
@@ -40,11 +41,13 @@ class ProfileController extends Controller
if ($request->has('avatar')) if ($request->has('avatar'))
{ {
if ($user->avatar) { if ($user->avatar) {
FileFacade::delete($user->avatar); File::delete($user->avatar);
} }
$destinationPath = 'avatar/' . $user->username; $destinationPath = 'avatar/' . $user->username;
$filename = time() .".". $request->file('avatar')->getClientOriginalExtension(); $filename = time() .".". $request->file('avatar')->getClientOriginalExtension();
$avatar = FileFacade::save($request->avatar, $destinationPath, $filename); $request->file('avatar')->storeAs($destinationPath, $filename, 'public');
$avatar = 'storage/'.$destinationPath ."/". $filename;
} }
$user->update([ $user->update([

View File

@@ -13,6 +13,7 @@ use Spatie\Permission\Traits\HasPermissions;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Models\UserActivityLog; use App\Models\UserActivityLog;
use App\Models\LogList; use App\Models\LogList;
use Illuminate\Support\Facades\URL;
class User extends Authenticatable class User extends Authenticatable
{ {
@@ -232,7 +233,8 @@ class User extends Authenticatable
public function avatarUrl(): ?string public function avatarUrl(): ?string
{ {
$avatar = $this->attributes['avatar']; $avatar = $this->attributes['avatar'];
return $avatar == null ? null : Storage::disk('public')->url($avatar); return $avatar == null ? null : URL::to('/') . '/' . $avatar;
} }
} }

View File

@@ -698,7 +698,7 @@ Route::get('/profile', function () {
// })->middleware(['auth', 'confirmUser']); // })->middleware(['auth', 'confirmUser']);
// Route::get('/winter-camp', 'View\WinterCampController@view')->middleware(['auth', 'confirmUser']); // Route::get('/winter-camp', 'View\WinterCampController@view')->middleware(['auth', 'confirmUser']);
// Route::get('/randd/voting/{id}', 'View\RandDController@showVoteSinglePage'); Route::get('/randd/voting/{id}', 'View\RandDController@showVoteSinglePage');
Route::get('bi', 'View\BiController@show'); Route::get('bi', 'View\BiController@show');
// Route::get('reports', function () { // Route::get('reports', function () {
@@ -806,7 +806,7 @@ Route::post('webapi/cmms/search', 'Api\CMMSController@search');
// //// RandD Voting API // //// RandD Voting API
// Route::post('webapi/randd/voting/{id}/start', 'Api\RandDVoting\AdminVoterController@startVoting'); // Route::post('webapi/randd/voting/{id}/start', 'Api\RandDVoting\AdminVoterController@startVoting');
// // Route::post('webapi/randd/voting/{id}/rejectProject', 'Api\RandDVoting\AdminVoterController@rejectProject'); // // Route::post('webapi/randd/voting/{id}/rejectProject', 'Api\RandDVoting\AdminVoterController@rejectProject');
// Route::middleware('cors:api')->post('webapi/randd/voting/{id}/store', 'Api\RandDVoting\VoterController@storeVoting'); Route::middleware('cors:api')->post('webapi/randd/voting/{id}/store', 'Api\RandDVoting\VoterController@storeVoting');
// Route::get('webapi/randd/voting/{id}/result', 'Api\RandDVoting\VoterController@showResult'); // Route::get('webapi/randd/voting/{id}/result', 'Api\RandDVoting\VoterController@showResult');
// Route::post('webapi/randd/voting/{id}/end', 'Api\RandDVoting\AdminVoterController@endVoting'); // Route::post('webapi/randd/voting/{id}/end', 'Api\RandDVoting\AdminVoterController@endVoting');

View File

@@ -208,10 +208,7 @@ class EditTest extends TestCase
$avatar = UploadedFile::fake()->create('image.jpg', 1024); $avatar = UploadedFile::fake()->create('image.jpg', 1024);
FileFacade::shouldReceive('save') Storage::fake();
->andReturn('image.jpg');
FileFacade::shouldReceive('delete');
$data = [ $data = [
'first_name' => $this->faker->firstName, 'first_name' => $this->faker->firstName,

View File

@@ -5,6 +5,7 @@ namespace Tests\Feature\V3\Profile;
use App\Models\User; use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Tests\TestCase; use Tests\TestCase;
@@ -33,7 +34,7 @@ class InfoTest extends TestCase
'degree' => $user->degree, 'degree' => $user->degree,
'mobile' => $user->mobile, 'mobile' => $user->mobile,
# an accessor has been defined in User model for User's avatar # an accessor has been defined in User model for User's avatar
'avatar' => Storage::disk('public')->url($user->avatar), 'avatar' => URL::to('/') . '/' . $user->avatar,
] ]
]); ]);
} }